Jenkins- job之间传参

简介: 前言:本文介绍插件: Parameterized Trigger plugin的具体使用方法。一、插件介绍Parameterized Trigger plugin插件可以让你在构建完成时触发新的Job构建,并以各种方式为新Job构建指定参数。

前言:

本文介绍插件: Parameterized Trigger plugin的具体使用方法。


一、插件介绍

Parameterized Trigger plugin插件可以让你在构建完成时触发新的Job构建,并以各种方式为新Job构建指定参数。
当然也可以添加多个配置:每个配置都有一个要触发的Job,触发时间的条件(基于当前构建的结果)和参数部分。


二、使用方法

1、项目Test_A,配置-构建后操作-配置如下信息:

选择【Trigger parameterized build on other projects】

【Projects to build】:项目名称
【Trigger when build is】:项目执行状态
【Add Parameters】:添加需要传的参数

1、【Predefined parameters】:预定义参数,后续的job的入参与当前job的参数名称不一致,或者有新参数的时候,可以使用该传参方式。
局限:后续job的入参的值要么固定,要么由环境变量和入参进行简单的组合获取,无法融入逻辑语句。
2、【Current build parameters】:后续job的入参和用到当前job的入参的时候,可是使用该传参方式。
局限:参数取决于当前的job
3、【Parameters from properties file】:若后续job的入参的值需要一定逻辑处理才能获取,那么,这种传参方式就特别好用了,比较灵活。
image.png本次传参例子为:JOB_NAME=${JOB_NAME}

2、项目Test_B,配置-参数化构建过程-配置如下信息:

选择【参数化构建过程】

【添加参数-字符参数】:选择字符参数
【名称】:输入参数名称JOB_NAME
image.png

3、项目Test_B,输出传入的参数验证。

选择【构建-Execute shell】

输出传参:echo ${JOB_NAME}
image.png

4、执行项目Test_A后,自动执行项目Test_B,并传入参数${JOB_NAME},查看项目Test_B输出结果。

项目Test_B输出结果如下:
image.png


三、预定义参数

我选择的参数为预定义参数Predefined parameters,那分别有哪些预定义参数可以用呢?

在Build模块下选择Execute shell--the list of available environment variables 选项,可以查看预定义参数信息,如下图:
image.png

如下,列出所有可用的预定义参数:

The following variables are available to shell scripts

BRANCH_NAME
For a multibranch project, this will be set to the name of the branch being built, for example in case you wish to deploy to production from master but not from feature branches; if corresponding to some kind of change request, the name is generally arbitrary (refer to CHANGE_ID and CHANGE_TARGET).

CHANGE_ID
For a multibranch project corresponding to some kind of change request, this will be set to the change ID, such as a pull request number, if supported; else unset.

CHANGE_URL
For a multibranch project corresponding to some kind of change request, this will be set to the change URL, if supported; else unset.
___

CHANGE_TITLE
For a multibranch project corresponding to some kind of change request, this will be set to the title of the change, if supported; else unset.
___

CHANGE_AUTHOR
For a multibranch project corresponding to some kind of change request, this will be set to the username of the author of the proposed change, if supported; else unset.
___

CHANGE_AUTHOR_DISPLAY_NAME
For a multibranch project corresponding to some kind of change request, this will be set to the human name of the author, if supported; else unset.
___

CHANGE_AUTHOR_EMAIL
For a multibranch project corresponding to some kind of change request, this will be set to the email address of the author, if supported; else unset.
___

CHANGE_TARGET
For a multibranch project corresponding to some kind of change request, this will be set to the target or base branch to which the change could be merged, if supported; else unset.
___

BUILD_NUMBER
The current build number, such as "153"
___

BUILD_ID
The current build ID, identical to BUILD_NUMBER for builds created in 1.597+, but a YYYY-MM-DD_hh-mm-ss timestamp for older builds
___

BUILD_DISPLAY_NAME
The display name of the current build, which is something like "#153" by default.
___

JOB_NAME
Name of the project of this build, such as "foo" or "foo/bar".
___

JOB_BASE_NAME
Short Name of the project of this build stripping off folder paths, such as "foo" for "bar/foo".
___

BUILD_TAG
String of "jenkins-${JOB_NAME}-${BUILD_NUMBER}". All forward slashes ("/") in the JOB_NAME are replaced with dashes ("-"). Convenient to put into a resource file, a jar file, etc for easier identification.
___

EXECUTOR_NUMBER
The unique number that identifies the current executor (among executors of the same machine) that’s carrying out this build. This is the number you see in the "build executor status", except that the number starts from 0, not 1.
___

NODE_NAME
Name of the agent if the build is on an agent, or "master" if run on master
___

NODE_LABELS
Whitespace-separated list of labels that the node is assigned.
___

WORKSPACE
The absolute path of the directory assigned to the build as a workspace.
___

JENKINS_HOME
The absolute path of the directory assigned on the master node for Jenkins to store data.
___

JENKINS_URL
Full URL of Jenkins, like http://server:port/jenkins/ (note: only available if Jenkins URL set in system configuration)
___

BUILD_URL
Full URL of this build, like http://server:port/jenkins/job/foo/15/ (Jenkins URL must be set)
___

JOB_URL
Full URL of this job, like http://server:port/jenkins/job/foo/ (Jenkins URL must be set)
___

GIT_COMMIT
The commit hash being checked out.
___

GIT_PREVIOUS_COMMIT
The hash of the commit last built on this branch, if any.
___

GIT_PREVIOUS_SUCCESSFUL_COMMIT
The hash of the commit last successfully built on this branch, if any.
___

GIT_BRANCH
The remote branch name, if any.
___

GIT_LOCAL_BRANCH
The local branch name being checked out, if applicable.
___

GIT_URL
The remote URL. If there are multiple, will be GIT_URL_1, GIT_URL_2, etc.
___

GIT_COMMITTER_NAME
The configured Git committer name, if any.
___

GIT_AUTHOR_NAME
The configured Git author name, if any.
___

GIT_COMMITTER_EMAIL
The configured Git committer email, if any.
___

GIT_AUTHOR_EMAIL
The configured Git author email, if any.
___

SVN_REVISION
Subversion revision number that's currently checked out to the workspace, such as "12345"
___

SVN_URL
Subversion URL that's currently checked out to the workspace.
----
以上~ 如果对你有帮助的话,点赞️吧~~

作者:搁浅
出处: http://www.cnblogs.com/xiaoxi-3-/
如果对您有帮助,请关注我的同名简书:https://www.jianshu.com/u/da1677475c27
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

目录
相关文章
|
运维 jenkins Devops
Jenkins创建多分支job
Jenkins创建多分支job
172 0
Jenkins创建多分支job
|
jenkins 持续交付
Jenkins(5)- 新建一个job并快速体验完整流程
Jenkins(5)- 新建一个job并快速体验完整流程
266 0
Jenkins(5)- 新建一个job并快速体验完整流程
|
jenkins Shell 持续交付
Jenkins 踩坑 | job 创建、参数化、定时构建及时区偏差问题解决
Jenkins 踩坑 | job 创建、参数化、定时构建及时区偏差问题解决
|
jenkins Shell 持续交付
Jenkins 踩坑 | job 创建、参数化、定时构建及时区偏差问题解决
1)启动 Jenkins 后在首页点击"开始创建一个新任务"。 2)输入任务名称,选择自由风格,点击“确定”。 1) 任意输入描述,然后勾选"丢弃旧的构建", 在"保持构建的最大个数中"输入 3。 1)勾选"参数化构建过程",选择添加"字符参数" 2)设置参数名称、默认值和描述 1)在"构建触发器"中勾选"定时构建",日程表中输入H2/ * * * *,表示每两分钟构建一次。 1)在构建中选择执
|
jenkins Shell 持续交付
Jenkins 踩坑 | job 创建、参数化、定时构建及时区偏差问题解决
1)启动 Jenkins 后在首页点击"开始创建一个新任务"。 2)输入任务名称,选择自由风格,点击“确定”。 1) 任意输入描述,然后勾选"丢弃旧的构建", 在"保持构建的最大个数中"输入 3。 1)勾选"参数化构建过程",选择添加"字符参数" 2)设置参数名称、默认值和描述 1)在"构建触发器"中勾选"定时构建",日程表中输入H2/ * * * *,表示每两分钟构建一次。 1)在构建中选择执
|
jenkins API 持续交付
jenkins 批量添加任务job
最近重构一个Scrapy爬虫项目,需要将300个spider的调度任务在jenkins中添加。这已经超过了手动一个一个添加任务的极限,是时候要借助工具批量添加了。
8519 0
|
安全 jenkins API
通过jenkins API去build一个job
背景 查看jenkins的api 直接访问 JENKINS_URL/job/JOB_NAME/api/ 就可以查看jenkins的api build一个job的话,是POST请求 JENKINS_URL/job/JOB_NAME/build 会提示: 这是jenkins的安全策略导致的,需要传递一个crumb    解决方法 有两个方案, 第一种方案: 1.
2751 0
|
jenkins Shell 持续交付
Jenkins不同job之间传递参数
有的时候不同job直接需要传递一个文件名或者路径,这个时候我们不需要传递文件实体,那这个路径如何传递呢?比如有如下两个项目,我想把A的工作目录传递给B,让B使用。 A job配置 首先需要安装一个Parameterized Trigger Plugin插件: 安装后重启。
2124 0
|
19天前
|
jenkins 持续交付 开发者
自动化部署:使用Jenkins和Docker实现持续集成与交付
【8月更文挑战第31天】本文旨在为读者揭示如何通过Jenkins和Docker实现自动化部署,从而加速软件开发流程。我们将从基础概念讲起,逐步深入到实际操作,确保即使是初学者也能跟上步伐。文章将提供详细的步骤说明和代码示例,帮助读者理解并应用这些工具来优化他们的工作流程。
|
19天前
|
持续交付 jenkins Devops
WPF与DevOps的完美邂逅:从Jenkins配置到自动化部署,全流程解析持续集成与持续交付的最佳实践
【8月更文挑战第31天】WPF与DevOps的结合开启了软件生命周期管理的新篇章。通过Jenkins等CI/CD工具,实现从代码提交到自动构建、测试及部署的全流程自动化。本文详细介绍了如何配置Jenkins来管理WPF项目的构建任务,确保每次代码提交都能触发自动化流程,提升开发效率和代码质量。这一方法不仅简化了开发流程,还加强了团队协作,是WPF开发者拥抱DevOps文化的理想指南。
39 1