Retrieve build number or artifacts of downstream build in Jenkins

落花浮王杯 提交于 2019-11-28 20:24:08

Just if any (else) stumples accross this question in the future:

When using the Parameterized Trigger Plugin as a build step, then if the trigger is configured with the "Block until the triggered projects finish their builds" enabled, the following Environment variables are made available for further build steps:

  • LAST_TRIGGERED_JOB_NAME="Last project started"
  • TRIGGERED_BUILD_NUMBER_{project name}="Last build number triggered"

from version 2.17 onwards

  • TRIGGERED_JOB_NAMES="Comma separated list of all triggered projects"
  • TRIGGERED_BUILD_NUMBERS_{project name}="Comma separated list of build numbers triggered"
  • TRIGGERED_BUILD_RESULT_{project name}="Last triggered build result of project"
  • TRIGGERED_BUILD_RESULT_{project name}RUN{build number}="Result of triggered build for build number"
  • TRIGGERED_BUILD_RUN_COUNT_{project name}="Number of builds triggered for the project"

See more info on the plugin website - linked in the question.

Found my own answer. Not as easy as plugin or an already-set variable, but it works.

Use the Jenkins XML API with depth=1 (very import to get the URLs fully traversed and all information available) and XPATH. Here is a sample of the URL I used:

http://jenkins/job/SMALLJOB/api/xml?depth=1&xpath=/freeStyleProject/build[action/cause/upstreamProject="%JOB_NAME%" and action/cause/upstreamBuild=%BUILD_ID%]/number/text()

This would return the build number of the right SMALLJOB (the one started by THIS BIGJOB). Then use that number in http download from Jenkins to get the archived build files.

You may refer to this functions :

Jenkins Build where you can find :

jenkinsapi.api.block_until_complete(jenkinsurl, jobs, maxwait=12000, interval=30, raise_on_timeout=True, username=None, password=None)

jenkinsapi.api.get_artifacts(jenkinsurl, jobid=None, build_no=None, username=None, password=None)

jenkinsapi.api.get_build(jenkinsurl, jobname, build_no, username=None, password=None)

jenkinsapi.api.get_latest_build(jenkinsurl, jobname, username=None, password=None)

jenkinsapi.api.get_latest_complete_build(jenkinsurl, jobname, username=None, password=None)

jenkinsapi.api.get_latest_test_results(jenkinsurl, jobname, username=None, password=None)

jenkinsapi.api.get_nested_view_from_url(url, username=None, password=None)

jenkinsapi.api.get_view_from_url(url, username=None, password=None)

jenkinsapi.api.grab_artifact(jenkinsurl, jobid, artifactid, targetdir, username=None, password=None)

jenkinsapi.api.install_artifacts(artifacts, dirstruct, installdir, basestaticurl)

jenkinsapi.api.search_artifact_by_regexp(jenkinsurl, jobid, artifactRegExp, username=None, password=None)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!