Jenkins - How to Get and Use Downstream Information

Performing a superior job called "A". On the successful completion of A test cases, which are the subsequent project "B". But when sending mail from B, we must include project details (project name, build number) in the mail. Thus, we can easily match / match the test run with the corresponding task upstream.

The bottom panel of the project displays the details below.

Started by upstream project Dev_RM_3.0_CI_Test build number 10
originally caused by:

I checked at https://wiki.jenkins-ci.org/display/JENKINS/Building+a+software+project . but could not find anything to inherit later.

An example job has been created with the information below to display the current job details.

echo $BUILD_NUMBER
echo $JOB_NAME
echo $BUILD_ID

But the way out

Building on master in workspace /var/lib/jenkins/workspace/env
[env] $ /bin/sh -xe /tmp/hudson970280339057643719.sh
+ echo 1
1
+ echo env
env
+ echo 1
1
Finished: SUCCESS
  1. , ?
  2. ?
+10
4

, ", Started by upstream project "Chained/1-First "build number 34", jenkins.

. DSL Pipelines, . , curl URL- jq .

, curl http://localhost: 8080/job/Chained/job/2-Second/17/api/json

"_class": "org.jenkinsci.plugins.workflow.job.WorkflowRun",
"actions": [{
  "_class": "hudson.model.CauseAction",
  "causes": [{
    "_class": "hudson.model.Cause$UpstreamCause",
    "shortDescription": "Started by upstream project \"Chained/1-First\" build number 34",
    "upstreamBuild": 34,
    "upstreamProject": "Chained/1-First",
    "upstreamUrl": "job/Chained/job/1-First/"
  }]
}

, :

node() {
    stage('downstream') {
        def upstream = currentBuild.rawBuild.getCause(hudson.model.Cause$UpstreamCause)
        echo upstream?.shortDescription
    }
}

, . , , , .

+12

, ( ), , ${MyParameter1} ${MyParameter2}.

:

  • . , "ParentJobName".
  • - "Trigger downstream " .
  • - " " " " # 2 , . : ParentJobName=${JOB_NAME}
  • , . ${ParentJobName}

. - , , , , , Copy Artifacts Plugin, Jenkins API groovy / ..

+9

@razboy: , Cause . Jenkins API . API @razboy grep, . Jenkins API . API, /api URL- : <jenkins_url>/job/<buildUrl>/<buildNumber>/api

   def buildUrl = env.BUILD_URL
   sh "wget $buildUrl -O currentConsole.txt"
   statusCode = sh returnStatus: true,script: 'cat currentConsole.txt | grep -q "Started by upstream project"'
   boolean startedByUpstream= statusCode==0
0

params.variableName , , . .

0

Source: https://habr.com/ru/post/1652862/


All Articles