Skip to main content

stage approval through API

Answered

Comments

2 comments

  • Ray Kivisto

    Hi Jothi,

    Using an example pipeline with a human input step:
    https://github.com/rkivisto/pipeline-deployment-demo

    If I have this setup as a multibranch Pipeline on my instance, and build number 2 of the master branch is waiting for human input, I can approve this using a script:

    ./approveInput.sh https://jenkinsURL rkivisto myAPIToken pipeline-deployment-demo/job/master 2 Deploy

    Here is the script approveInput.sh:

    ```
    #!/bin/bash
    JENKINS_URL=$1
    USER=$2
    API_TOKEN=$3
    JOB_NAME=$4
    BUILD_ID=$5
    INPUT_ID=$6

    SUBMIT_CAPTION=Proceed
    JENKINS_CRUMB=$(wget -q --auth-no-challenge --user ${USER} --password ${API_TOKEN} --output-document - "${JENKINS_URL}/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")
    curl -X POST --user ${USER}:${API_TOKEN} -H "${JENKINS_CRUMB}" -d proceed="${SUBMIT_CAPTION}" -d json="{}" "${JENKINS_URL}/job/${JOB_NAME}/${BUILD_ID}/input/${INPUT_ID}/submit"
    ```

    The INPUT_ID comes from your pipeline, in this case it has "id: 'Deploy'" as per https://github.com/rkivisto/pipeline-deployment-demo/blob/125969500cfdfa60e647f8bf9863a7bcb5e8164b/Jenkinsfile#L28

    0
  • Jothi Laksh

    Thank you.

    It is working.

    0

Please sign in to leave a comment.

About CloudBees Support

Our Support Engineers are available to help with any questions or problems you may have with any of our products.