Skip to content

Commit

Permalink
Adding jenkins-wait-job input (#2)
Browse files Browse the repository at this point in the history
* Adding jenkins-wait-job input
  • Loading branch information
Alec4r authored Apr 14, 2021
1 parent 4a2b967 commit 5a56427
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ Jenkins job name
**i.e** Production-deployment-pipeline
**(Required)**

### `job-params`
### `jenkins-wait-job`
**Not mandatory**

Wait for the job build status

**values**
```
"wait" #Default
"no-wait"
```

### `jenkins-job-params`

**Not mandatory**

Expand All @@ -41,6 +52,7 @@ Set jenkins params as JSON string:
* FAILURE
* SUCCESS
* ABORTED
* EXECUTED


## Example usage
Expand All @@ -53,4 +65,9 @@ Set jenkins params as JSON string:
jenkins-user: ${{ secrets.JENKINS_USER }}
jenkins-job: ${{ secrets.JENKINS_JOB }}
jenkins-job-params: "{'stringparam': 'stringvalue', 'booleanparam': false}"
jenkins-wait-job: "no-wait"
```

## Notes:
If your job needs params and you want to use the default params, you will need to set Jenkins-job-params: "{'any_param': 'any_value'}"
otherwise, you will receive a 400 Bad request error.
8 changes: 7 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ inputs:
jenkins-job-params:
description: "Jenkins job params. JSON string. i.e '{'STRING_PARAM': 'value1', 'BOOLEAN_PARAM': false}' "
required: false
default: '{}'
jenkins-wait-job:
description: "Wait for the job build status"
required: false
default: 'wait'
outputs:
job_status:
description: 'Jenkins job build status'
Expand All @@ -29,6 +34,7 @@ runs:
- ${{ inputs.jenkins-user}}
- ${{ inputs.jenkins-job }}
- ${{ inputs.jenkins-job-params}}
- ${{ inputs.jenkins-wait-job }}
branding:
icon: 'arrow-up-right'
color: 'yellow'
color: 'yellow'
8 changes: 7 additions & 1 deletion build_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def mandatory_arg(argv):
JENKINS_JOB_NAME = mandatory_arg(sys.argv[4])

# Optional args
JENKINS_JOB_PARAMS = sys.argv[5] if len(sys.argv) > 5 else '{}'
JENKINS_JOB_PARAMS = sys.argv[5] if len(sys.argv) >= 5 else '{}'
JENKINS_WAIT_JOB = sys.argv[6] if len(sys.argv) >= 6 else "wait"

# Set Jenkins Connection
repository = ServerJenkinsRepository(url=JENKINS_URL, token=JENKINS_TOKEN, username=JENKINS_USERNAME)
Expand All @@ -34,6 +35,11 @@ def mandatory_arg(argv):
build_number = finder.number()
print(f"BUILD NUMBER: {build_number}")

if JENKINS_WAIT_JOB == "no-wait" and build_number:
print("Job status is : EXECUTED")
print("::set-output name=job_status::EXECUTED")
exit(0)

# Get build status
while not (status := finder.exec(build_number)):
time.sleep(1)
Expand Down
3 changes: 2 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
python-jenkins==1.7.0
jenkins==1.0.2
requests==2.25.1
requests==2.25.1
argparse==1.4.0

0 comments on commit 5a56427

Please sign in to comment.