diff --git a/README.md b/README.md index 6243b10..14a13ea 100644 --- a/README.md +++ b/README.md @@ -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** @@ -41,6 +52,7 @@ Set jenkins params as JSON string: * FAILURE * SUCCESS * ABORTED +* EXECUTED ## Example usage @@ -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. \ No newline at end of file diff --git a/action.yml b/action.yml index f564d38..ecda378 100644 --- a/action.yml +++ b/action.yml @@ -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' @@ -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' \ No newline at end of file + color: 'yellow' diff --git a/build_job.py b/build_job.py index 50c8a18..cb32987 100644 --- a/build_job.py +++ b/build_job.py @@ -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) @@ -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) diff --git a/requirements/base.txt b/requirements/base.txt index f408b1e..b4f24b4 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,3 +1,4 @@ python-jenkins==1.7.0 jenkins==1.0.2 -requests==2.25.1 \ No newline at end of file +requests==2.25.1 +argparse==1.4.0 \ No newline at end of file