Compare commits

...

57 Commits

Author SHA1 Message Date
appleboy 24e8004b58 docs: refactor codebase and update documentation
- Update installation command from `go get` to `go install` in README.md

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 22:19:13 +08:00
appleboy dff06f164a docs: improve CI/CD pipeline and test reliability
- Update Docker image source to `ghcr.io/appleboy/drone-jenkins` in README.md

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 22:16:58 +08:00
appleboy 895becb9a7 docs: update README badges and improve documentation
- Add lint and testing badge to the README
- Remove build status badge from the README
- Remove Docker pulls badge from the README
- Remove microbadger badge from the README

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 22:11:42 +08:00
appleboy 5344ca212b ci: improve test coverage and CI workflow reliability
- Remove `macos-latest` from the OS matrix in the lint workflow

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 21:05:40 +08:00
appleboy b370179bda refactor: refactor codebase for improved compatibility and efficiency
- Replace `ioutil.ReadAll` with `io.ReadAll` in `jenkins.go`
- Ignore the return value of `godotenv.Load` in `main.go`
- Ignore the return value of `godotenv.Overload` in `main.go`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:34:57 +08:00
appleboy d9f9a4ddc5 ci: refactor CI pipeline to remove Docker Hub dependencies
- Remove Docker Hub login step
- Remove Docker Hub image reference

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:32:00 +08:00
appleboy 51db9357f0 ci: refactor and optimize CI/CD pipeline
- Update Docker login action from version 2 to version 3 in GitHub workflow

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:30:58 +08:00
appleboy 0326a42ccb chore: upgrade Go version and dependencies in project
- Remove Go 1.21 from the lint workflow
- Update Go version to 1.22 in go.mod
- Upgrade dependencies: `godotenv` to v1.5.1, `testify` to v1.9.0, `cli` to v1.22.15
- Add new indirect dependencies: `go-md2man/v2`, `go-spew`, `go-difflib`, `blackfriday/v2`, `yaml.v3`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:22:51 +08:00
appleboy 4f822500f2 style: refactor codebase for improved consistency and clarity
- Reorder imports in `jenkins_test.go` and `plugin_test.go` to move `assert` import to the end
- Remove unnecessary empty line in `plugin.go`

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:22:05 +08:00
appleboy f932a0ef24 build: refactor build system and update formatting tools
- Change `GOFMT` tool from `gofmt` to `gofumpt`
- Remove DockerHub deployment configurations
- Add detection and setup for Go environment variables
- Add conditional flags and executable naming based on OS
- Update `fmt` and `fmt-check` targets to use `gofumpt`
- Remove `lint`, `misspell-check`, and `misspell` targets
- Update `test` target to remove dependency on `fmt-check`
- Change `install` and `build` targets to use `GOFILES` instead of `SOURCES`
- Update `$(EXECUTABLE)` target to output to `bin/`
- Remove various `release` and `docker` related targets

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:21:32 +08:00
appleboy 5122d14617 ci: enhance CI with multi-OS and Go version testing
- Rename `testing` job to `test`
- Add matrix strategy to run tests on multiple OS and Go versions
- Replace `actions/checkout@v4` with `actions/setup-go@v5` for setting up Go
- Add caching for Go build and module files using `actions/cache@v4`
- Change test command from `make test` to `go test -v -covermode=atomic -coverprofile=coverage.out`
- Add flags to `codecov/codecov-action@v4` for OS and Go version

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:21:23 +08:00
appleboy 65d16c52a3 chore: improve code quality and testing robustness
- Add hadolint configuration file with rules DL3018 and DL3008 ignored

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:15:35 +08:00
appleboy 86574d9456 build: consolidate Dockerfiles for multi-architecture support
- Add a new Dockerfile for multi-architecture support using Alpine 3.20
- Remove Dockerfile for linux.amd64
- Remove Dockerfile for linux.arm
- Remove Dockerfile for linux.arm64
- Remove Dockerfile for windows
- Remove Docker manifest template file

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:15:23 +08:00
appleboy 1cbab46f5c ci: add CI/CD workflows and dependency management
- Add funding configuration file with multiple supported platforms
- Add Dependabot configuration for GitHub Actions and Go modules with weekly updates
- Add CodeQL analysis workflow for Go language
- Add Docker image build and push workflow for multiple platforms
- Add GoReleaser workflow for automated releases on tag push
- Add linting and testing workflow with Go setup, Dockerfile linting, and Codecov integration

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 15:13:35 +08:00
appleboy 7c4ff53a64 chore: clean up obsolete configuration files
- Remove `.drone.jsonnet` file
- Remove `.drone.yml` file
- Remove `.editorconfig` file
- Remove `.revive.toml` file
- Remove `pipeline.libsonnet` file

Signed-off-by: appleboy <appleboy.tw@gmail.com>
2024-10-04 14:28:23 +08:00
Bo-Yi Wu 4d6399606b chore: upgrade to go1.15
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2020-09-26 12:40:20 +08:00
Bo-Yi Wu 118b8f9b35 chore: upgrade to go1.14 2020-07-18 09:48:04 +08:00
Bo-Yi Wu daf0401e30 chore: load env from /run/drone/env path 2020-07-18 09:46:57 +08:00
Bo-Yi Wu 685cc312e3 chore(makefile): remove GOPACKAGE variable 2020-02-01 17:58:28 +08:00
Bo-Yi Wu cac1337e91 docs: update diff format 2019-10-19 10:17:11 +08:00
Bo-Yi Wu 742e20ea9c update docs
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-30 11:30:04 +08:00
Bo-Yi Wu 6ca333982b add arch
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-30 11:27:34 +08:00
Bo-Yi Wu 5e1b16bcf5 update docs
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-30 11:26:48 +08:00
Bo-Yi Wu 7b357075fe add arch
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-30 11:24:02 +08:00
Bo-Yi Wu bd482e9c7a docs: update
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-09-30 11:08:41 +08:00
Bo-Yi Wu 0d110e195c docs: update 2019-09-30 07:52:18 +08:00
Bo-Yi Wu 7441ec1d9b chore: upgrade go module 2019-09-30 07:47:20 +08:00
Bo-Yi Wu ee6e15d448 chore: support github actions 2019-09-30 07:45:18 +08:00
Bo-Yi Wu e8184fbb5c chore: upgrade to go1.13 2019-09-30 07:43:28 +08:00
Bo-Yi Wu 326b4c2dc5 chore(docker): replace ADD with COPY 2019-03-04 21:43:41 +08:00
Bo-Yi Wu e70b95f505 chore: add lint check
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2019-03-04 16:12:01 +08:00
Bo-Yi Wu beee0b43a6 chore: mirror changes 2019-03-02 10:53:03 +08:00
Bo-Yi Wu 93c81b3ee6 docs: create new jenkins token 2019-03-02 09:15:59 +08:00
Bo-Yi Wu 9e55d9c14f docs: add jenkins command 2019-03-02 09:11:42 +08:00
Bo-Yi Wu e67398a6a3 docs: update drone badge 2019-03-01 08:54:32 +08:00
Bo-Yi Wu ded8530d8e chore(docker): upgrade drone and dockerfile 2019-03-01 08:53:17 +08:00
Bo-Yi Wu eac91dc0af feat: switch to go module 2019-03-01 08:41:04 +08:00
Bo-Yi Wu c81cb4142a fix gopath 2018-12-28 00:00:05 +08:00
Bo-Yi Wu ead7714d9a remove branch
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2018-11-11 16:29:09 +08:00
Bo-Yi Wu 96b11d47cd feat: check return err. 2018-11-11 11:38:23 +08:00
Bo-Yi Wu 3362d46d26 feat: support go module in go 1.11 2018-11-11 11:36:00 +08:00
Bo-Yi Wu bba1fb3a6e feat: support windows image 2018-11-11 11:17:01 +08:00
Bo-Yi Wu 0af129e9d8 feat(ddocker): support arm and i386 version 2018-11-11 11:08:44 +08:00
Bo-Yi Wu 6777964976 add maintainer label.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-10-05 11:33:53 +08:00
Bo-Yi Wu 9eca070b01 add notify
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-06-24 23:01:01 +08:00
Bo-Yi Wu 4d3054d832 add empty line.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-08 14:05:01 +08:00
Bo-Yi Wu b007a60843 support group build (#19)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-07 15:19:17 +08:00
Bo-Yi Wu 18b163fd7b add fmt check command (#18)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-07 12:52:57 +08:00
Bo-Yi Wu 03bcfacb96 remove travis build.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-07 12:22:10 +08:00
Bo-Yi Wu 042c5d632c upgrade drone config (#17)
* upgrade drone config

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* remove glide config

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-06 23:31:30 +08:00
Bo-Yi Wu fc238fb606 feat: replpace glide to govendor (#16) 2017-05-06 23:15:28 +08:00
Bo-Yi Wu bc987b6d01 remove drone sig file (#14)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2017-05-06 22:57:45 +08:00
Bo-Yi Wu 6e58cda4fe feat: Add unconvert command 2017-01-28 11:47:12 +08:00
Bo-Yi Wu 396719ff0f docs: [ci skip] remove secret section. 2017-01-20 15:06:16 +08:00
Bo-Yi Wu 8e578266db docs: [ci skip] update readme. 2017-01-17 11:14:19 +08:00
Bo-Yi Wu 7d040a545c docs: add drone documents. (#11) 2017-01-17 10:58:32 +08:00
Bo-Yi Wu e07592691c fix: Enforce custom LDFLAGS within makefile 2017-01-17 10:35:58 +08:00
31 changed files with 779 additions and 328 deletions
+2
View File
@@ -0,0 +1,2 @@
*
!release/
-80
View File
@@ -1,80 +0,0 @@
workspace:
base: /srv/app
path: src/github.com/appleboy/drone-jenkins
pipeline:
clone:
image: plugins/git
tags: true
# restore the cache from an sftp server
restore_cache:
image: appleboy/drone-sftp-cache
pull: true
restore: true
mount: [ .glide, vendor ]
ignore_branch: true
test:
image: appleboy/golang-testing
pull: true
environment:
TAGS: netgo
GOPATH: /srv/app
commands:
- make dep_install
- make vet
- make lint
- make test
- make coverage
- make build
# build binary for docker image
- make static_build
when:
event: [ push, tag, pull_request ]
release:
image: appleboy/golang-testing
pull: true
environment:
TAGS: netgo
GOPATH: /srv/app
commands:
- make release
when:
event: [ tag ]
branch: [ refs/tags/* ]
docker:
image: plugins/docker
repo: ${DRONE_REPO}
tags: [ '${DRONE_TAG}' ]
when:
event: [ tag ]
branch: [ refs/tags/* ]
docker:
image: plugins/docker
repo: ${DRONE_REPO}
tags: [ 'latest' ]
when:
event: [ push ]
branch: [ master ]
github:
image: plugins/github-release
files:
- dist/release/*
when:
event: [ tag ]
branch: [ refs/tags/* ]
# rebuild the cache on the sftp server
rebuild_cache:
image: appleboy/drone-sftp-cache
pull: true
rebuild: true
mount: [ .glide, vendor ]
ignore_branch: true
when:
branch: master
-1
View File
@@ -1 +0,0 @@
eyJhbGciOiJIUzI1NiJ9.d29ya3NwYWNlOgogIGJhc2U6IC9zcnYvYXBwCiAgcGF0aDogc3JjL2dpdGh1Yi5jb20vYXBwbGVib3kvZHJvbmUtamVua2lucwoKcGlwZWxpbmU6CiAgY2xvbmU6CiAgICBpbWFnZTogcGx1Z2lucy9naXQKICAgIHRhZ3M6IHRydWUKCiAgIyByZXN0b3JlIHRoZSBjYWNoZSBmcm9tIGFuIHNmdHAgc2VydmVyCiAgcmVzdG9yZV9jYWNoZToKICAgIGltYWdlOiBhcHBsZWJveS9kcm9uZS1zZnRwLWNhY2hlCiAgICBwdWxsOiB0cnVlCiAgICByZXN0b3JlOiB0cnVlCiAgICBtb3VudDogWyAuZ2xpZGUsIHZlbmRvciBdCiAgICBpZ25vcmVfYnJhbmNoOiB0cnVlCgogIHRlc3Q6CiAgICBpbWFnZTogYXBwbGVib3kvZ29sYW5nLXRlc3RpbmcKICAgIHB1bGw6IHRydWUKICAgIGVudmlyb25tZW50OgogICAgICBUQUdTOiBuZXRnbwogICAgICBHT1BBVEg6IC9zcnYvYXBwCiAgICBjb21tYW5kczoKICAgICAgLSBtYWtlIGRlcF9pbnN0YWxsCiAgICAgIC0gbWFrZSB2ZXQKICAgICAgLSBtYWtlIGxpbnQKICAgICAgLSBtYWtlIHRlc3QKICAgICAgLSBtYWtlIGNvdmVyYWdlCiAgICAgIC0gbWFrZSBidWlsZAogICAgICAjIGJ1aWxkIGJpbmFyeSBmb3IgZG9ja2VyIGltYWdlCiAgICAgIC0gbWFrZSBzdGF0aWNfYnVpbGQKICAgIHdoZW46CiAgICAgIGV2ZW50OiBbIHB1c2gsIHRhZywgcHVsbF9yZXF1ZXN0IF0KCiAgcmVsZWFzZToKICAgIGltYWdlOiBhcHBsZWJveS9nb2xhbmctdGVzdGluZwogICAgcHVsbDogdHJ1ZQogICAgZW52aXJvbm1lbnQ6CiAgICAgIFRBR1M6IG5ldGdvCiAgICAgIEdPUEFUSDogL3Nydi9hcHAKICAgIGNvbW1hbmRzOgogICAgICAtIG1ha2UgcmVsZWFzZQogICAgd2hlbjoKICAgICAgZXZlbnQ6IFsgdGFnIF0KICAgICAgYnJhbmNoOiBbIHJlZnMvdGFncy8qIF0KCiAgZG9ja2VyOgogICAgaW1hZ2U6IHBsdWdpbnMvZG9ja2VyCiAgICByZXBvOiAke0RST05FX1JFUE99CiAgICB0YWdzOiBbICcke0RST05FX1RBR30nIF0KICAgIHdoZW46CiAgICAgIGV2ZW50OiBbIHRhZyBdCiAgICAgIGJyYW5jaDogWyByZWZzL3RhZ3MvKiBdCgogIGRvY2tlcjoKICAgIGltYWdlOiBwbHVnaW5zL2RvY2tlcgogICAgcmVwbzogJHtEUk9ORV9SRVBPfQogICAgdGFnczogWyAnbGF0ZXN0JyBdCiAgICB3aGVuOgogICAgICBldmVudDogWyBwdXNoIF0KICAgICAgYnJhbmNoOiBbIG1hc3RlciBdCgogIGdpdGh1YjoKICAgIGltYWdlOiBwbHVnaW5zL2dpdGh1Yi1yZWxlYXNlCiAgICBmaWxlczoKICAgICAgLSBkaXN0L3JlbGVhc2UvKgogICAgd2hlbjoKICAgICAgZXZlbnQ6IFsgdGFnIF0KICAgICAgYnJhbmNoOiBbIHJlZnMvdGFncy8qIF0KCiAgIyByZWJ1aWxkIHRoZSBjYWNoZSBvbiB0aGUgc2Z0cCBzZXJ2ZXIKICByZWJ1aWxkX2NhY2hlOgogICAgaW1hZ2U6IGFwcGxlYm95L2Ryb25lLXNmdHAtY2FjaGUKICAgIHB1bGw6IHRydWUKICAgIHJlYnVpbGQ6IHRydWUKICAgIG1vdW50OiBbIC5nbGlkZSwgdmVuZG9yIF0KICAgIGlnbm9yZV9icmFuY2g6IHRydWUKICAgIHdoZW46CiAgICAgIGJyYW5jaDogbWFzdGVyCg.6JgOuyvwKlOK6Hs1hD2dFaWGrtnRjVClYH-jQk-Wgq4
-42
View File
@@ -1,42 +0,0 @@
# unifying the coding style for different editors and IDEs => editorconfig.org
; indicate this is the root of the project
root = true
###########################################################
; common
###########################################################
[*]
charset = utf-8
end_of_line = LF
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
###########################################################
; make
###########################################################
[Makefile]
indent_style = tab
[makefile]
indent_style = tab
###########################################################
; markdown
###########################################################
[*.md]
trim_trailing_whitespace = false
###########################################################
; golang
###########################################################
[*.go]
indent_style = tab
+13
View File
@@ -0,0 +1,13 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ['https://www.paypal.me/appleboy46']
+10
View File
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
- package-ecosystem: gomod
directory: /
schedule:
interval: weekly
+54
View File
@@ -0,0 +1,54 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [master]
pull_request:
# The branches below must be a subset of the branches above
branches: [master]
schedule:
- cron: "41 23 * * 6"
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: ["go"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
+64
View File
@@ -0,0 +1,64 @@
name: Docker Image
on:
push:
branches:
- master
tags:
- "v*"
pull_request:
branches:
- "master"
jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: "^1"
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build binary
run: |
make build_linux_amd64
make build_linux_arm64
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: docker-meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
+32
View File
@@ -0,0 +1,32 @@
name: Goreleaser
on:
push:
tags:
- "*"
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: "^1"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+67
View File
@@ -0,0 +1,67 @@
name: Lint and Testing
on:
push:
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: "^1"
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --verbose
- uses: hadolint/hadolint-action@v3.1.0
name: hadolint for Dockerfile
with:
dockerfile: docker/Dockerfile
test:
strategy:
matrix:
os: [ubuntu-latest]
go: [1.22, 1.23]
include:
- os: ubuntu-latest
go-build: ~/.cache/go-build
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
env:
GO111MODULE: on
GOPROXY: https://proxy.golang.org
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: actions/cache@v4
with:
path: |
${{ matrix.go-build }}
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run Tests
run: |
go test -v -covermode=atomic -coverprofile=coverage.out
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
flags: ${{ matrix.os }},go-${{ matrix.go }}
-1
View File
@@ -22,7 +22,6 @@ _testmain.go
*.exe
*.test
*.prof
vendor
drone-jenkins
coverage.txt
.env
+3
View File
@@ -0,0 +1,3 @@
ignored:
- DL3018
- DL3008
-22
View File
@@ -1,22 +0,0 @@
sudo: required
language: go
go:
- 1.6.x
- 1.7.x
- tip
cache:
directories:
- vendor
- ${HOME}/.glide
before_install:
- mkdir -p $GOPATH/bin
- curl https://glide.sh/get | sh
install:
- make dep_install
script:
- make test
+63
View File
@@ -0,0 +1,63 @@
---
date: 2019-10-19T00:00:00+00:00
title: Jenkins
author: appleboy
tags: [ infrastructure, trigger, jenkins ]
repo: appleboy/drone-jenkins
logo: jenkins.svg
image: appleboy/drone-jenkins
---
The Jenkins plugin allows you to trigger Jenkins job automatically. The below pipeline configuration demonstrates simple usage:
```yaml
- name: trigger jenkins job
image: appleboy/drone-jenkins
settings:
url: http://example.com
user: appleboy
token: xxxxxxxxxx
job: drone-jenkins-plugin-job
```
Example configuration with multiple jobs:
```diff
- name: trigger jenkins job
image: appleboy/drone-jenkins
settings:
url: http://example.com
user: appleboy
token: xxxxxxxxxx
job:
+ - drone-jenkins-plugin-job-1
+ - drone-jenkins-plugin-job-2
```
Example configuration with jobs in the folder:
```diff
- name: trigger jenkins job
image: appleboy/drone-jenkins
settings:
url: http://example.com
user: appleboy
token: xxxxxxxxxx
+ job: folder_name/job_name
```
It will trigger the URL of Jenkins job like as `http://example.com/job/folder_name/job/job_name/`
## Parameter Reference
url
: jenkins server base url.
user
: jenkins user account
token
: jenkins user token
job
: jenkins job name
-5
View File
@@ -1,5 +0,0 @@
FROM centurylink/ca-certs
ADD drone-jenkins /
ENTRYPOINT ["/drone-jenkins"]
-8
View File
@@ -1,8 +0,0 @@
FROM armhfbuild/alpine:3.4
RUN apk update && \
apk add ca-certificates && \
rm -rf /var/cache/apk/*
ADD drone-jenkins /bin/
ENTRYPOINT ["/bin/drone-jenkins"]
+54 -78
View File
@@ -1,17 +1,9 @@
.PHONY: test drone-jenkins build fmt vet errcheck lint install update release-dirs release-build release-copy release-check release coverage
DIST := dist
EXECUTABLE := drone-jenkins
# for dockerhub
DEPLOY_ACCOUNT := appleboy
DEPLOY_IMAGE := $(EXECUTABLE)
TARGETS ?= linux darwin windows
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
SOURCES ?= $(shell find . -name "*.go" -type f)
TAGS ?=
LDFLAGS += -X 'main.Version=$(VERSION)'
GOFMT ?= gofumpt -l -s -w
GO ?= go
GOFILES := $(shell find . -name "*.go" -type f)
HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
ifneq ($(shell uname), Darwin)
EXTLDFLAGS = -extldflags "-static" $(null)
@@ -19,96 +11,80 @@ else
EXTLDFLAGS =
endif
ifeq ($(HAS_GO), GO)
GOPATH ?= $(shell $(GO) env GOPATH)
export PATH := $(GOPATH)/bin:$(PATH)
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
endif
ifeq ($(OS), Windows_NT)
GOFLAGS := -v -buildmode=exe
EXECUTABLE ?= $(EXECUTABLE).exe
else ifeq ($(OS), Windows)
GOFLAGS := -v -buildmode=exe
EXECUTABLE ?= $(EXECUTABLE).exe
else
GOFLAGS := -v
EXECUTABLE ?= $(EXECUTABLE)
endif
ifneq ($(DRONE_TAG),)
VERSION ?= $(DRONE_TAG)
else
VERSION ?= $(shell git describe --tags --always || git rev-parse --short HEAD)
endif
TAGS ?=
LDFLAGS ?= -X 'main.Version=$(VERSION)'
all: build
fmt:
find . -name "*.go" -type f -not -path "./vendor/*" | xargs gofmt -s -w
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt; \
fi
$(GOFMT) -w $(GOFILES)
vet:
go vet $(PACKAGES)
$(GO) vet ./...
errcheck:
@which errcheck > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/kisielk/errcheck; \
.PHONY: fmt-check
fmt-check:
@hash gofumpt > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) install mvdan.cc/gofumpt; \
fi
errcheck $(PACKAGES)
lint:
@which golint > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/golang/lint/golint; \
fi
for PKG in $(PACKAGES); do golint -set_exit_status $$PKG || exit 1; done;
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;
test:
for PKG in $(PACKAGES); do go test -v -cover -coverprofile $$GOPATH/src/$$PKG/coverage.txt $$PKG || exit 1; done;
@$(GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
html:
go tool cover -html=coverage.txt
dep_install:
glide install
dep_update:
glide up
install: $(SOURCES)
go install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
install: $(GOFILES)
$(GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
build: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
go build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
$(EXECUTABLE): $(GOFILES)
$(GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o bin/$@
release: release-dirs release-build release-copy release-check
build_linux_amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/amd64/$(DEPLOY_IMAGE)
release-dirs:
mkdir -p $(DIST)/binaries $(DIST)/release
build_linux_arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm64/$(DEPLOY_IMAGE)
release-build:
@which gox > /dev/null; if [ $$? -ne 0 ]; then \
go get -u github.com/mitchellh/gox; \
fi
gox -os="$(TARGETS)" -arch="amd64 386" -tags="$(TAGS)" -ldflags="-s -w $(LDFLAGS)" -output="$(DIST)/binaries/$(EXECUTABLE)-$(VERSION)-{{.OS}}-{{.Arch}}"
release-copy:
$(foreach file,$(wildcard $(DIST)/binaries/$(EXECUTABLE)-*),cp $(file) $(DIST)/release/$(notdir $(file));)
release-check:
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
# for docker.
static_build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $(DEPLOY_IMAGE)
docker_image:
docker build -t $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE) .
docker: static_build docker_image
docker_deploy:
ifeq ($(tag),)
@echo "Usage: make $@ tag=<tag>"
@exit 1
endif
# deploy image
docker tag $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):latest $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
docker push $(DEPLOY_ACCOUNT)/$(DEPLOY_IMAGE):$(tag)
coverage:
sed -i '/main.go/d' coverage.txt
curl -s https://codecov.io/bash > .codecov && \
chmod +x .codecov && \
./.codecov -f coverage.txt
build_linux_arm:
CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 $(GO) build -a -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o release/linux/arm/$(DEPLOY_IMAGE)
clean:
go clean -x -i ./...
rm -rf coverage.txt $(EXECUTABLE) $(DIST) vendor
$(GO) clean -x -i ./...
rm -rf coverage.txt $(EXECUTABLE) $(DIST)
version:
@echo $(VERSION)
+37 -28
View File
@@ -1,9 +1,31 @@
# drone-jenkins
[![GoDoc](https://godoc.org/github.com/appleboy/drone-jenkins?status.svg)](https://godoc.org/github.com/appleboy/drone-jenkins) [![Build Status](http://drone.wu-boy.com/api/badges/appleboy/drone-jenkins/status.svg)](http://drone.wu-boy.com/appleboy/drone-jenkins) [![codecov](https://codecov.io/gh/appleboy/drone-jenkins/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-jenkins) [![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-jenkins)](https://goreportcard.com/report/github.com/appleboy/drone-jenkins) [![Docker Pulls](https://img.shields.io/docker/pulls/appleboy/drone-jenkins.svg)](https://hub.docker.com/r/appleboy/drone-jenkins/) [![](https://images.microbadger.com/badges/image/appleboy/drone-jenkins.svg)](https://microbadger.com/images/appleboy/drone-jenkins "Get your own image badge on microbadger.com")
![logo](./images/logo.png)
[![Lint and Testing](https://github.com/appleboy/drone-jenkins/actions/workflows/lint.yml/badge.svg)](https://github.com/appleboy/drone-jenkins/actions/workflows/lint.yml)
[![GoDoc](https://godoc.org/github.com/appleboy/drone-jenkins?status.svg)](https://godoc.org/github.com/appleboy/drone-jenkins)
[![codecov](https://codecov.io/gh/appleboy/drone-jenkins/branch/master/graph/badge.svg)](https://codecov.io/gh/appleboy/drone-jenkins)
[![Go Report Card](https://goreportcard.com/badge/github.com/appleboy/drone-jenkins)](https://goreportcard.com/report/github.com/appleboy/drone-jenkins)
[Drone](https://github.com/drone/drone) plugin for trigger [Jenkins](https://jenkins.io/) jobs.
## Setup the Jenkins Server
Setup the Jenkins server using the docker command:
```sh
$ docker run \
--name jenkins \
-d --restart always \
-p 8080:8080 -p 50000:50000 \
-v /data/jenkins:/var/jenkins_home \
jenkins/jenkins:lts
```
Please make sure that you create the `/data/jenkins` before starting the Jenkins. Create the new API token as below:
![jenkins token](./images/jenkins-token.png)
## Build or Download a binary
The pre-compiled binaries can be downloaded from [release page](https://github.com/appleboy/drone-jenkins/releases). Support the following OS type.
@@ -14,41 +36,28 @@ The pre-compiled binaries can be downloaded from [release page](https://github.c
With `Go` installed
```sh
go install github.com/appleboy/drone-jenkins
```
$ go get -u -v github.com/appleboy/drone-jenkins
```
or build the binary with the following command:
```
$ make build
```sh
make build
```
## Docker
Build the docker image with the following commands:
```
$ make docker
```
Please note incorrectly building the image for the correct x64 linux and with
GCO disabled will result in an error when running the Docker image:
```
docker: Error response from daemon: Container command
'/bin/drone-jenkins' not found or does not exist..
```sh
make docker
```
## Usage
There are three ways to trigger jenkins jobs.
* [usage from binary](#usage-from-binary)
* [usage from docker](#usage-from-docker)
* [usage from drone ci](#usage-from-drone-ci)
<a name="usage-from-binary"></a>
### Usage from binary
trigger single job.
@@ -72,7 +81,6 @@ drone-jenkins \
--job drone-jenkins-plugin-2
```
<a name="usage-from-docker"></a>
### Usage from docker
trigger single job.
@@ -83,7 +91,7 @@ docker run --rm \
-e JENKINS_USER=appleboy
-e JENKINS_TOKEN=xxxxxxx
-e JENKINS_JOB=drone-jenkins-plugin
appleboy/drone-jenkins
ghcr.io/appleboy/drone-jenkins
```
trigger multiple jobs.
@@ -94,15 +102,14 @@ docker run --rm \
-e JENKINS_USER=appleboy
-e JENKINS_TOKEN=xxxxxxx
-e JENKINS_JOB=drone-jenkins-plugin-1,drone-jenkins-plugin-2
appleboy/drone-jenkins
ghcr.io/appleboy/drone-jenkins
```
<a name="usage-from-drone-ci"></a>
### Usage from drone ci
Execute from the working directory:
```
```sh
docker run --rm \
-e PLUGIN_URL=http://example.com \
-e PLUGIN_USER=xxxxxxx \
@@ -110,13 +117,15 @@ docker run --rm \
-e PLUGIN_JOB=xxxxxxx \
-v $(pwd):$(pwd) \
-w $(pwd) \
appleboy/drone-jenkins
ghcr.io/appleboy/drone-jenkins
```
You can get more [information](DOCS.md) about how to use scp plugin in drone.
## Testing
Test the package with the following command:
```
$ make test
```sh
make test
```
+20
View File
@@ -0,0 +1,20 @@
FROM alpine:3.20
ARG TARGETOS
ARG TARGETARCH
LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Drone Jenkins Plugin" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"
LABEL org.opencontainers.image.source=https://github.com/appleboy/drone-jenkins
LABEL org.opencontainers.image.description="Drone Jenkins"
LABEL org.opencontainers.image.licenses=MIT
RUN apk add --no-cache ca-certificates && \
rm -rf /var/cache/apk/*
COPY release/${TARGETOS}/${TARGETARCH}/drone-jenkins /bin/
ENTRYPOINT ["/bin/drone-jenkins"]
Generated
-22
View File
@@ -1,22 +0,0 @@
hash: 33ad75827779208440690394b479984ac46bc9d6c817389fb6d98f9fddbdf813
updated: 2017-01-16T10:47:58.426849408+08:00
imports:
- name: github.com/joho/godotenv
version: a01a834e1654b4c9ca5b3ad05159445cc9c7ad08
subpackages:
- autoload
- name: github.com/urfave/cli
version: 0bdeddeeb0f650497d603c4ad7b20cfe685682f6
testImports:
- name: github.com/davecgh/go-spew
version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9
subpackages:
- spew
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages:
- difflib
- name: github.com/stretchr/testify
version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0
subpackages:
- assert
-13
View File
@@ -1,13 +0,0 @@
package: github.com/appleboy/drone-jenkins
import:
- package: github.com/joho/godotenv
version: ^1.0.0
subpackages:
- autoload
- package: github.com/urfave/cli
version: ^1.19.1
testImport:
- package: github.com/stretchr/testify
version: ^1.1.4
subpackages:
- assert
+17
View File
@@ -0,0 +1,17 @@
module github.com/appleboy/drone-jenkins
go 1.22
require (
github.com/joho/godotenv v1.5.1
github.com/stretchr/testify v1.9.0
github.com/urfave/cli v1.22.15
)
require (
github.com/cpuguy83/go-md2man/v2 v2.0.5 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
+30
View File
@@ -0,0 +1,30 @@
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.5 h1:ZtcqGrnekaHpVLArFSe4HK5DoKx1T0rq2DwVB0alcyc=
github.com/cpuguy83/go-md2man/v2 v2.0.5/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli v1.22.15 h1:nuqt+pdC/KqswQKhETJjo7pvn/k4xMUxgW6liI7XpnM=
github.com/urfave/cli v1.22.15/go.mod h1:wSan1hmo5zeyLGBjRJbzRTNk8gwoYa2B9n4q9dmRIc0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

+283
View File
File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 29 KiB

+2 -2
View File
@@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"strings"
@@ -58,7 +58,7 @@ func (jenkins *Jenkins) parseResponse(resp *http.Response, body interface{}) (er
return
}
data, err := ioutil.ReadAll(resp.Body)
data, err := io.ReadAll(resp.Body)
if err != nil {
return
}
+2 -2
View File
@@ -1,10 +1,10 @@
package main
import (
"github.com/stretchr/testify/assert"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseJobPath(t *testing.T) {
+19 -18
View File
@@ -1,10 +1,10 @@
package main
import (
"log"
"os"
"github.com/joho/godotenv"
_ "github.com/joho/godotenv/autoload"
"github.com/urfave/cli"
)
@@ -12,12 +12,21 @@ import (
var Version string
func main() {
// Load env-file if it exists first
if filename, found := os.LookupEnv("PLUGIN_ENV_FILE"); found {
_ = godotenv.Load(filename)
}
if _, err := os.Stat("/run/drone/env"); err == nil {
_ = godotenv.Overload("/run/drone/env")
}
app := cli.NewApp()
app.Name = "jenkins plugin"
app.Usage = "trigger jenkins jobs"
app.Copyright = "Copyright (c) 2017 Bo-Yi Wu"
app.Copyright = "Copyright (c) 2019 Bo-Yi Wu"
app.Authors = []cli.Author{
cli.Author{
{
Name: "Bo-Yi Wu",
Email: "appleboy.tw@gmail.com",
},
@@ -28,28 +37,22 @@ func main() {
cli.StringFlag{
Name: "host",
Usage: "jenkins base url",
EnvVar: "PLUGIN_URL,JENKINS_URL",
EnvVar: "PLUGIN_URL,JENKINS_URL,INPUT_URL",
},
cli.StringFlag{
Name: "user,u",
Usage: "jenkins username",
EnvVar: "PLUGIN_USER,JENKINS_USER",
EnvVar: "PLUGIN_USER,JENKINS_USER,INPUT_USER",
},
cli.StringFlag{
Name: "token,t",
Usage: "jenkins token",
EnvVar: "PLUGIN_TOKEN,JENKINS_TOKEN",
EnvVar: "PLUGIN_TOKEN,JENKINS_TOKEN,INPUT_TOKEN",
},
cli.StringSliceFlag{
Name: "job,j",
Usage: "jenkins job",
EnvVar: "PLUGIN_JOB,JENKINS_JOB",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
EnvVar: "ENV_FILE",
Value: ".env",
EnvVar: "PLUGIN_JOB,JENKINS_JOB,INPUT_JOB",
},
}
@@ -86,14 +89,12 @@ REPOSITORY:
Github: https://github.com/appleboy/drone-line
`
app.Run(os.Args)
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
plugin := Plugin{
BaseURL: c.String("host"),
Username: c.String("user"),
+5 -4
View File
@@ -16,7 +16,7 @@ type (
)
func trimElement(keys []string) []string {
var newKeys []string
newKeys := []string{}
for _, value := range keys {
value = strings.Trim(value, " ")
@@ -31,7 +31,6 @@ func trimElement(keys []string) []string {
// Exec executes the plugin.
func (p Plugin) Exec() error {
if len(p.BaseURL) == 0 || len(p.Username) == 0 || len(p.Token) == 0 {
return errors.New("missing jenkins config")
}
@@ -49,8 +48,10 @@ func (p Plugin) Exec() error {
jenkins := NewJenkins(auth, p.BaseURL)
for _, value := range jobs {
jenkins.trigger(value, nil)
for _, v := range jobs {
if err := jenkins.trigger(v, nil); err != nil {
return err
}
}
return nil
+2 -2
View File
@@ -1,9 +1,9 @@
package main
import (
"github.com/stretchr/testify/assert"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMissingConfig(t *testing.T) {