Skip to content

Commit

Permalink
Add async option
Browse files Browse the repository at this point in the history
  • Loading branch information
ertrzyiks committed Jul 1, 2021
1 parent 1958956 commit 1c43399
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ jobs:
job_params: '{"param_1":"value_1", "param_2":"value_2"}'
job_timeout: "3600" # Default 30 sec. (optional)
```


### Inputs

* `jenkins_url`: **required** Jenkins instance URL
* `jenkins_user`: **required** User name used for authentication
* `jenkins_token`: **required** User token used for authentication
* `job_name`: **required** for jobs stored in a folder use `{folder-name}/job/{job-name}`
* `job_params`: **required** Valid JSON with key-value params passed to the job
* `job_timeout`: Number of seconds to wait for the action to finish (Default 30)
* `async`: Set to true if you want to just trigger the job and dont wait for it to complete (Default false)

### Outputs

* `jenkins_job_url`: jenkins build URL if the scheduled job starts executing within given `job_timeout`
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ inputs:
description: 'Jenkins job timeout period. Default 30 seconds'
required: false
default: '30'
async:
description: 'Set to true if you want to just trigger the job without waiting for it to finish'
required: false
default: false
outputs:
jenkins_job_url:
description: 'URL to the job details'
runs:
using: 'docker'
image: 'Dockerfile'
Expand Down
7 changes: 6 additions & 1 deletion jenkins/job_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Jenkins
class JobClient

attr_reader :jenkins_url, :jenkins_user, :jenkins_token, :job_name, :job_params, :job_timeout
attr_reader :async_mode, :jenkins_url, :jenkins_user, :jenkins_token, :job_name, :job_params, :job_timeout

DEFAULT_TIMEOUT = 30
INTERVAL_SECONDS = 10
Expand All @@ -13,6 +13,7 @@ def initialize(args)
@jenkins_user = args['INPUT_JENKINS_USER']
@jenkins_token = args['INPUT_JENKINS_TOKEN']
@job_name = args['INPUT_JOB_NAME']
@async_mode = args['INPUT_ASYNC'].to_s == 'true'
@job_params = JSON.parse(args['INPUT_JOB_PARAMS'])
@job_timeout = args['INPUT_JOB_TIMEOUT'] || DEFAULT_TIMEOUT
end
Expand All @@ -21,7 +22,11 @@ def call
crumb = get_crumb
queue_item_location = queue_job(crumb, job_name, job_params)
job_run_url = get_job_run_url(queue_item_location, job_timeout)
puts "::set-output name=jenkins_job_url::#{job_run_url}"
puts "Job run URL: #{job_run_url}"

exit(0) if @async_mode

job_progress(job_run_url, job_timeout)
exit(0)
end
Expand Down

0 comments on commit 1c43399

Please sign in to comment.