Answers: <p>When setting up the remote trigger, you have to click "Block until the remote triggered projects finish their builds."</p>
  
  <p><a href="https://i.sstatic.net/BSnYD.png" rel="noreferrer"><img src="https://i.sstatic.net/BSnYD.png" alt="Remote Parameterized Job"></a></p>
  
Answers: CC BY-SA 3.0
Answers: 2017-03-10T09:14:42.730Z
Answers: thanks, i may have the wrong end of the stick.. that plug in seems to be for triggering remote builds from jenkins itself? In my scenario, the build is triggered from a request from Bamboo, but we would like that request to hold until the build completes and return the state of the build.
Answers: osmorgan
Answers: CC BY-SA 3.0
Answers: 2017-03-11T17:47:06.873Z
Answers: Ah, I understand now.  Unfortunately I don't think the API works that way, if you look at how that plugin for Jenkins is developed you'll see it triggers the remote job and then polls for status until it's finished.
Answers: Travis Thompson
Answers: CC BY-SA 3.0
Answers: 2017-03-12T18:47:19.480Z
Answers: Thanks, i ended up making this https://github.com/owenmorgan/jenkins-remote-builder
Answers: osmorgan
Answers: CC BY-SA 3.0
Answers: 2017-03-14T22:50:54.847Z
Answers: @osmorgan: you should describe that in an answer (with a bit of summary, not only the link) and accept it.
Answers: Dan Cornilescu
Answers: CC BY-SA 3.0
Answers: 2017-03-16T09:02:29.293Z
Answers: sheesh.. its in the question.. and there is a description in the link. see you at stackoverflow.
Answers: osmorgan
Answers: CC BY-SA 3.0
Answers: 2017-03-09T18:02:55.703Z
Answers: 2017-03-09T18:02:55.703Z
Answers: Travis Thompson
Answers: <p>If you need to trigger a job from CLI and wait for its completion you can use "Jenkins CLI" (see <a href="https://support.cloudbees.com/hc/en-us/articles/228392127-How-to-wait-for-build-to-finish-when-triggering-from-CLI-" rel="nofollow noreferrer">here</a>).</p>
  
  <p>However jenkins CLI does not support promotions so for them I came up with the following script:</p>
  
  <pre><code>#!/bin/bash
  # Trigger a promotion and wait for its completion
  #
  # For triggering jobs jenkins cli is sufficient: https://support.cloudbees.com/hc/en-us/articles/228392127-How-to-wait-for-build-to-finish-when-triggering-from-CLI-
  #
  # The script is dependent on the current jenkins implementation of:
  # - the promotion web page (links for triggering/re-executing the promotions)
  # - the behaviour of the XML of the promotion status
  #
  # The behaviour of the job run status XML is:
  #   - if the the promotion is not yet been triggered than the response is 404 not found
  #   - is the the promotion has been triggered
  #     - ... but it's still waiting for an executor:  the response is 404 not found or &lt;duration&gt; is empty
  #     - ... and has started:                         &lt;duration&gt; is empty or 0
  #     - ... and it's finished:                       &lt;duration&gt; is a non-zero number
  #
  #
  #  run syntax:
  #    ./trigger_promotion_and_wait_for_completion.sh \
  #       &lt;job_name&gt; \
  #       &lt;job_run_number_to_promote&gt; \
  #       &lt;promotion_name&gt; \
  #       &lt;jenkins_user&gt; \
  #       &lt;jenkins_pwd&gt; \
  #       &lt;jenkins_url&gt; \
  #       &lt;script_workspace_folder&gt; \
  #       '{"name": "prom_param_1", "value": "stringvalue" } , {"name": "prom_param_2", "value": true }'
  #
  #   example:
  #    ./trigger_promotion_and_wait_for_completion.sh \
  #       job1 \
  #       22 \
  #       promotion1 \
  #       admin \
  #       password \
  #       http://localhost:8080/jenkins/ \
  #       . \
  #       '{"name": "prom_param_1", "value": "stringvalue" } , {"name": "prom_param_2", "value": true }'
  
  
  
  set -uexo pipefail
  
  #other debug options:
  #PS4='+\t '
  #set -v
  
  JOB_NAME="${1}"
  JOB_RUN_NUMBER="${2}"
  DEPLOY_PROMOTION_NAME="${3}"
  BUILDER_USER="${4}"
  BUILDER_PASSWORD="${5}"
  JENKINS_URL="${6}"
  WORKSPACE_FOLDER="${7}"
  PROMOTION_ARGUMENTS="${8}"
  
  TIMEOUT=900
  
  
  echo "retrieving the promotion nextBuildNumber (so we can poll the promotion status and check if it's finished)..."
  PROMOTION_RUN_NUMBER="$( curl -s  -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}job/${JOB_NAME}/promotion/process/${DEPLOY_PROMOTION_NAME}/api/xml"  | grep -P  '&lt;nextBuildNumber&gt;(.*)&lt;/nextBuildNumber'   | sed -re 's/.*&lt;nextBuildNumber&gt;(.*)&lt;\/nextBuildNumber.*/\1/g' )"
  
  
  
  
  echo "running the promotion..."
  echo 'only the first promotion can be triggered with "Approve", while subsequent promotions are triggered with "Re-execute promotion"'
  echo 'so we check in the web page if the approve link is present'
  
  #the link to search in the web page
  PROMOTION_APPROVE_STRING="promotionProcess/${DEPLOY_PROMOTION_NAME}/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve"
  
  PROM_STATUS_URL="${JENKINS_URL}job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/"
  
  if curl -s -vvv -u${BUILDER_USER}:${BUILDER_PASSWORD}  "${PROM_STATUS_URL}" | grep "${PROMOTION_APPROVE_STRING}" ; then
      echo "The job has not yet been promoted, triggering it with 'Approve'"
      WEB_PATH="job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/promotionProcess/${DEPLOY_PROMOTION_NAME}/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve"
      SUBMIT="Approve"
  else
      echo "The job has already been promoted, triggering it with 'Re-execute promotion'"
      WEB_PATH="job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/${DEPLOY_PROMOTION_NAME}/build"
      SUBMIT="Re-execute+promotion"
  fi
  
  
  #note for the troubleshooting: in case the following curl fails then the error cause can be found near the string "stack trace"
  CURL_OUTPUT="$(  curl -s -vvv -XPOST -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}${WEB_PATH}"  \
                         --data 'json={
                                   "parameter": [
                                                  '"${PROMOTION_ARGUMENTS}"'
                                                ]
                                      }&amp;Submit='"${SUBMIT}" 2&gt;&amp;1 )"
  
  if ( echo "${CURL_OUTPUT}" |  grep -P "&lt; HTTP/1.1 5\d\d" ) || ( echo "${CURL_OUTPUT}" |  grep -P "&lt; HTTP/1.1 4\d\d" ) ; then
    echo  'error in triggering the job/promotion! exiting...'
    exit 1
  else
    echo  'curl good'
  fi
  
  
  
  echo "checking promotion status until promotion is finished"
  FINISHED=no
  
  
  INITIAL_TIME="$(date +%s)"
  while [ "${FINISHED}" != "ok" ]
  do
      sleep 2
  
  
      #checking if promotion is finished (we check the value of &lt;duration&gt; XML element in the job run status)
      ERROR="" ; DURATION="$(curl -s  -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/${DEPLOY_PROMOTION_NAME}/promotionBuild/${PROMOTION_RUN_NUMBER}/api/xml"    | grep -Po  '&lt;duration&gt;.*&lt;/duration&gt;'   | sed -re  's/&lt;duration&gt;(.*)&lt;\/duration&gt;/\1/g' )"   || ERROR="yes"
      if [[ $ERROR == "yes" ]] ; then
        echo " the promotion has been queued but not yet started, waiting for it to start..."
        curl -s  -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/${DEPLOY_PROMOTION_NAME}/promotionBuild/${PROMOTION_RUN_NUMBER}/api/xml"
        ERROR=""
        continue
      fi  ;   ERROR=""
  
  
  
  
      #we interrupt the polling of the job/promotion status if the promotion
      #  - is terminated
      #  - is taking too long (there is some problem)
      #(in the XML of the job run status the &lt;duration&gt; XML element value is initially empty, than it is 0, and eventually is the number of seconds of the run duration )
  
      POLLING_TIME="$(date +%s)"
      let "ELAPSED_TIME=POLLING_TIME-INITIAL_TIME"
      echo "ELAPSED_TIME=${ELAPSED_TIME}"
  
      if  (( ${ELAPSED_TIME} \&gt; $TIMEOUT ))  ; then
        echo "error: the promotion has taken too long... exiting"
        exit 1
      fi
  
      if  [[ "${DURATION}" != "" ]] ; then
        re='^[0-9]+$'
        if [[ $DURATION =~ $re ]] ; then
          if (( "${DURATION}" \&gt; "0" )) ; then
            FINISHED=ok
          else
            : #do nothing (the value of &lt;duration&gt; is 0 , that is the job/promotion has been started in a slave and is still running)
          fi
        else
          echo "error: the promotion duration is not a number. exiting..."
          exit 1
        fi
      else
        :  # the job/promotion has not yet started
      fi
  
      echo "waiting for the promotion to finish..."
  done
  
  echo "Promotion finished"
  
  
  
  echo "Promotion output:"
  curl -s  -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/${DEPLOY_PROMOTION_NAME}/promotionBuild/${PROMOTION_RUN_NUMBER}/consoleText" &gt; ${WORKSPACE_FOLDER}/promotionOutput
  
  cat ${WORKSPACE_FOLDER}/promotionOutput
  
  if [[ ! "$(tail -n1 ${WORKSPACE_FOLDER}/promotionOutput)" =~ "SUCCESS"  ]] ; then
        echo "Promotion did not successfully terminate"
        exit 1
  else
        echo "Promotion successfully terminated"
  fi
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2018-08-25T14:31:55.210Z
Answers: 2018-08-25T14:37:02.980Z
Answers: 2018-08-25T14:37:02.980Z
Answers: Giuliano
Answers: <p>I've created the <a href="https://github.com/owenmorgan/jenkins-remote-builder" rel="noreferrer">jenkins-remote-builder</a> script which will follow your remote build to completion.</p>
  <p>Some more details about it (from its <a href="https://github.com/owenmorgan/jenkins-remote-builder/blob/master/README.md" rel="noreferrer">README.md</a>):</p>
  <blockquote>
  <h2>Example</h2>
  <pre><code>jenkins=https://user:pass@jenkins.mydomain.com:8080
  jenkins_job=MyApp-Deploy
  
  environment=dev
  application=myapp
  revision=9fd71f63b351b8208264daf86d292ced580a2f60
  
  ./jenkins_remote_trigger.sh \
              -h ${jenkins} \
              -j ${jenkins_job} \
              -p &quot;ENVIRONMENT=${environment}&amp;APPLICATION=${application}&amp;REVISION=${revision}&quot;
  </code></pre>
  <h2>Usage:</h2>
  <pre><code>-h HOST     | --host=HOST                       Jenkins host
  -j JOBNAME  | --jobname=test-build-job          The name of the jenkins job to trigger
  -p JOBPARAM | --jobparam=environment=uat&amp;test=1 Jenkins job paramiters
  -q          | --quiet                           Don't output any status messages
  </code></pre>
  </blockquote>
  
Answers: CC BY-SA 3.0
Answers: 2017-03-16T09:11:07.620Z
Answers: A bit a summary on how it works would be better ;)
Answers: Tensibai
Answers: CC BY-SA 3.0
Answers: 2017-03-20T09:12:44.403Z
Answers: Please review the edit I applied to your (interesting!) answer, but which I think did have a risk of getting deleted (via moderation) because it was pretty much a link-only answer (as indicated somehow by the comment from @Tensibai also).
Answers: Pierre.Vriens
Answers: CC BY-SA 3.0
Answers: 2017-03-16T09:03:48.417Z
Answers: 2017-03-20T09:02:20.457Z
Answers: 2020-06-18T08:28:10.803Z
Answers: osmorgan
Body: <p>I am attempting to trigger a parameterized Jenkins build from Bamboo, doing the below:</p>
  
  <blockquote>
    <p>POST - 
    <code>http://jenkins-url.com/job/jobname/buildWithParameters?ENVIRONMENT=dev&amp;APPLICATION=hello-world</code></p>
  </blockquote>
  
  <p>But I will get a 201 instantly which tells me that the build was created. How do I make this request wait and return the success status of the build instead of the fire and forget? </p>
  
  <p>It is apparently possible as per <a href="https://github.com/morficus/Parameterized-Remote-Trigger-Plugin" rel="noreferrer">Parameterized-Remote-Trigger-Plugin</a>:</p>
  
  <p><a href="https://i.sstatic.net/lcoWp.png" rel="noreferrer"><img src="https://i.sstatic.net/lcoWp.png" alt="enter image description here"></a></p>
  
  <p>Edit:
  created this in the end if you need it.
  <a href="https://github.com/owenmorgan/jenkins-remote-builder" rel="noreferrer">https://github.com/owenmorgan/jenkins-remote-builder</a></p>
  
Tags: <jenkins><jenkins-plugins><bamboo>
Title: How to not "fire and forget" when doing a remote trigger of a Jenkins build?
UserDisplayName: osmorgan
ThreadText: # How to not "fire and forget" when doing a remote trigger of a Jenkins build?
  
  (Asked by: username_0 on 2017-03-09)
  
  I am attempting to trigger a parameterized Jenkins build from Bamboo, doing the below:
  
  > POST -
  > `http://jenkins-url.com/job/jobname/buildWithParameters?ENVIRONMENT=dev&APPLICATION=hello-world`
  
  But I will get a 201 instantly which tells me that the build was created. How do I make this request wait and return the success status of the build instead of the fire and forget?
  
  It is apparently possible as per [Parameterized-Remote-Trigger-Plugin](https://github.com/morficus/Parameterized-Remote-Trigger-Plugin):
  
  [![enter image description here](https://i.sstatic.net/lcoWp.png)](https://i.sstatic.net/lcoWp.png)
  
  Edit:
  created this in the end if you need it.
  <https://github.com/owenmorgan/jenkins-remote-builder>
  
  **Tags:** jenkins, jenkins-plugins, bamboo
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_0 on 2017-03-16. Score: 6 | Accepted answer
  
  I've created the [jenkins-remote-builder](https://github.com/owenmorgan/jenkins-remote-builder) script which will follow your remote build to completion.
  
  Some more details about it (from its [README.md](https://github.com/owenmorgan/jenkins-remote-builder/blob/master/README.md)):
  
  > ## Example
  >
  > ```
  > jenkins=https://user:pass@jenkins.mydomain.com:8080
  > jenkins_job=MyApp-Deploy
  >
  > environment=dev
  > application=myapp
  > revision=9fd71f63b351b8208264daf86d292ced580a2f60
  >
  > ./jenkins_remote_trigger.sh \
  >             -h ${jenkins} \
  >             -j ${jenkins_job} \
  >             -p "ENVIRONMENT=${environment}&APPLICATION=${application}&REVISION=${revision}"
  >
  > ```
  >
  > ## Usage:
  >
  > ```
  > -h HOST     | --host=HOST                       Jenkins host
  > -j JOBNAME  | --jobname=test-build-job          The name of the jenkins job to trigger
  > -p JOBPARAM | --jobparam=environment=uat&test=1 Jenkins job paramiters
  > -q          | --quiet                           Don't output any status messages
  >
  > ```
  
  > **Comments:**
  > **username_4**: A bit a summary on how it works would be better ;)  
  > **username_5**: Please review the edit I applied to your (interesting!) answer, but which I think did have a risk of getting deleted (via moderation) because it was pretty much a link-only answer (as indicated somehow by the comment from @username_4 also).  
  
  ---
  
  ### Answer by username_1 on 2017-03-09. Score: 5
  
  When setting up the remote trigger, you have to click "Block until the remote triggered projects finish their builds."
  
  [![Remote Parameterized Job](https://i.sstatic.net/BSnYD.png)](https://i.sstatic.net/BSnYD.png)
  
  > **Comments:**
  > **username_0**: thanks, i may have the wrong end of the stick.. that plug in seems to be for triggering remote builds from jenkins itself? In my scenario, the build is triggered from a request from Bamboo, but we would like that request to hold until the build completes and return the state of the build.  
  > **username_1**: Ah, I understand now.  Unfortunately I don't think the API works that way, if you look at how that plugin for Jenkins is developed you'll see it triggers the remote job and then polls for status until it's finished.  
  > **username_0**: Thanks, i ended up making this https://github.com/owenmorgan/jenkins-remote-builder  
  > **username_2**: @username_0: you should describe that in an answer (with a bit of summary, not only the link) and accept it.  
  > **username_0**: sheesh.. its in the question.. and there is a description in the link. see you at stackoverflow.  
  
  ---
  
  ### Answer by username_3 on 2018-08-25. Score: 1
  
  If you need to trigger a job from CLI and wait for its completion you can use "Jenkins CLI" (see [here](https://support.cloudbees.com/hc/en-us/articles/228392127-How-to-wait-for-build-to-finish-when-triggering-from-CLI-)).
  
  However jenkins CLI does not support promotions so for them I came up with the following script:
  
  ```
  #!/bin/bash
  # Trigger a promotion and wait for its completion
  #
  # For triggering jobs jenkins cli is sufficient: https://support.cloudbees.com/hc/en-us/articles/228392127-How-to-wait-for-build-to-finish-when-triggering-from-CLI-
  #
  # The script is dependent on the current jenkins implementation of:
  # - the promotion web page (links for triggering/re-executing the promotions)
  # - the behaviour of the XML of the promotion status
  #
  # The behaviour of the job run status XML is:
  #   - if the the promotion is not yet been triggered than the response is 404 not found
  #   - is the the promotion has been triggered
  #     - ... but it's still waiting for an executor:  the response is 404 not found or <duration> is empty
  #     - ... and has started:                         <duration> is empty or 0
  #     - ... and it's finished:                       <duration> is a non-zero number
  #
  #
  #  run syntax:
  #    ./trigger_promotion_and_wait_for_completion.sh \
  #       <job_name> \
  #       <job_run_number_to_promote> \
  #       <promotion_name> \
  #       <jenkins_user> \
  #       <jenkins_pwd> \
  #       <jenkins_url> \
  #       <script_workspace_folder> \
  #       '{"name": "prom_param_1", "value": "stringvalue" } , {"name": "prom_param_2", "value": true }'
  #
  #   example:
  #    ./trigger_promotion_and_wait_for_completion.sh \
  #       job1 \
  #       22 \
  #       promotion1 \
  #       admin \
  #       password \
  #       http://localhost:8080/jenkins/ \
  #       . \
  #       '{"name": "prom_param_1", "value": "stringvalue" } , {"name": "prom_param_2", "value": true }'
  
  set -uexo pipefail
  
  #other debug options:
  #PS4='+\t '
  #set -v
  
  JOB_NAME="${1}"
  JOB_RUN_NUMBER="${2}"
  DEPLOY_PROMOTION_NAME="${3}"
  BUILDER_USER="${4}"
  BUILDER_PASSWORD="${5}"
  JENKINS_URL="${6}"
  WORKSPACE_FOLDER="${7}"
  PROMOTION_ARGUMENTS="${8}"
  
  TIMEOUT=900
  
  echo "retrieving the promotion nextBuildNumber (so we can poll the promotion status and check if it's finished)..."
  PROMOTION_RUN_NUMBER="$( curl -s  -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}job/${JOB_NAME}/promotion/process/${DEPLOY_PROMOTION_NAME}/api/xml"  | grep -P  '<nextBuildNumber>(.*)</nextBuildNumber'   | sed -re 's/.*<nextBuildNumber>(.*)<\/nextBuildNumber.*/\1/g' )"
  
  echo "running the promotion..."
  echo 'only the first promotion can be triggered with "Approve", while subsequent promotions are triggered with "Re-execute promotion"'
  echo 'so we check in the web page if the approve link is present'
  
  #the link to search in the web page
  PROMOTION_APPROVE_STRING="promotionProcess/${DEPLOY_PROMOTION_NAME}/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve"
  
  PROM_STATUS_URL="${JENKINS_URL}job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/"
  
  if curl -s -vvv -u${BUILDER_USER}:${BUILDER_PASSWORD}  "${PROM_STATUS_URL}" | grep "${PROMOTION_APPROVE_STRING}" ; then
      echo "The job has not yet been promoted, triggering it with 'Approve'"
      WEB_PATH="job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/promotionProcess/${DEPLOY_PROMOTION_NAME}/promotionCondition/hudson.plugins.promoted_builds.conditions.ManualCondition/approve"
      SUBMIT="Approve"
  else
      echo "The job has already been promoted, triggering it with 'Re-execute promotion'"
      WEB_PATH="job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/${DEPLOY_PROMOTION_NAME}/build"
      SUBMIT="Re-execute+promotion"
  fi
  
  #note for the troubleshooting: in case the following curl fails then the error cause can be found near the string "stack trace"
  CURL_OUTPUT="$(  curl -s -vvv -XPOST -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}${WEB_PATH}"  \
                         --data 'json={
                                   "parameter": [
                                                  '"${PROMOTION_ARGUMENTS}"'
                                                ]
                                      }&Submit='"${SUBMIT}" 2>&1 )"
  
  if ( echo "${CURL_OUTPUT}" |  grep -P "< HTTP/1.1 5\d\d" ) || ( echo "${CURL_OUTPUT}" |  grep -P "< HTTP/1.1 4\d\d" ) ; then
    echo  'error in triggering the job/promotion! exiting...'
    exit 1
  else
    echo  'curl good'
  fi
  
  echo "checking promotion status until promotion is finished"
  FINISHED=no
  
  INITIAL_TIME="$(date +%s)"
  while [ "${FINISHED}" != "ok" ]
  do
      sleep 2
  
      #checking if promotion is finished (we check the value of <duration> XML element in the job run status)
      ERROR="" ; DURATION="$(curl -s  -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/${DEPLOY_PROMOTION_NAME}/promotionBuild/${PROMOTION_RUN_NUMBER}/api/xml"    | grep -Po  '<duration>.*</duration>'   | sed -re  's/<duration>(.*)<\/duration>/\1/g' )"   || ERROR="yes"
      if [[ $ERROR == "yes" ]] ; then
        echo " the promotion has been queued but not yet started, waiting for it to start..."
        curl -s  -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/${DEPLOY_PROMOTION_NAME}/promotionBuild/${PROMOTION_RUN_NUMBER}/api/xml"
        ERROR=""
        continue
      fi  ;   ERROR=""
  
      #we interrupt the polling of the job/promotion status if the promotion
      #  - is terminated
      #  - is taking too long (there is some problem)
      #(in the XML of the job run status the <duration> XML element value is initially empty, than it is 0, and eventually is the number of seconds of the run duration )
  
      POLLING_TIME="$(date +%s)"
      let "ELAPSED_TIME=POLLING_TIME-INITIAL_TIME"
      echo "ELAPSED_TIME=${ELAPSED_TIME}"
  
      if  (( ${ELAPSED_TIME} \> $TIMEOUT ))  ; then
        echo "error: the promotion has taken too long... exiting"
        exit 1
      fi
  
      if  [[ "${DURATION}" != "" ]] ; then
        re='^[0-9]+$'
        if [[ $DURATION =~ $re ]] ; then
          if (( "${DURATION}" \> "0" )) ; then
            FINISHED=ok
          else
            : #do nothing (the value of <duration> is 0 , that is the job/promotion has been started in a slave and is still running)
          fi
        else
          echo "error: the promotion duration is not a number. exiting..."
          exit 1
        fi
      else
        :  # the job/promotion has not yet started
      fi
  
      echo "waiting for the promotion to finish..."
  done
  
  echo "Promotion finished"
  
  echo "Promotion output:"
  curl -s  -u${BUILDER_USER}:${BUILDER_PASSWORD} "${JENKINS_URL}job/${JOB_NAME}/${JOB_RUN_NUMBER}/promotion/${DEPLOY_PROMOTION_NAME}/promotionBuild/${PROMOTION_RUN_NUMBER}/consoleText" > ${WORKSPACE_FOLDER}/promotionOutput
  
  cat ${WORKSPACE_FOLDER}/promotionOutput
  
  if [[ ! "$(tail -n1 ${WORKSPACE_FOLDER}/promotionOutput)" =~ "SUCCESS"  ]] ; then
        echo "Promotion did not successfully terminate"
        exit 1
  else
        echo "Promotion successfully terminated"
  fi
  
  ```
  
  
  ---
  
  