Jenkins "execute shell command" 部分中字符串参数的使用
Usage of string parameter in "execute shell command" section of Jenkins
我为名为 "Job_Name" 的 jenkin 作业配置了一个字符串参数。
我想检查传递给 jenkins "execute shell command" 部分参数的值。
我当前的 shell 命令如下图所示。
Shell 命令:
if [ "${Job_Name}" == "RSProductPreprocessor" ]; then
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i hosts/dev playbook_deployRSProductPreProcessor.yml -v --extra-vars "RSProductPreProcessorVersion=${Number_Of_RSProductPreProcessor_Build_To_Deploy}"
fi
但是当我 运行 这份工作时,我收到如下回复。
+ '[' '' == RSProductPreprocessor ']'
Finished: SUCCESS
要使 if 条件正常工作,应该做什么。请指教
您有几件事需要解决
单击 shell 下的 link 查看可用的环境变量
这是我的一些
BUILD_NUMBER
The current build number, such as "153"
BUILD_ID
The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss)
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". (To strip off folder paths from a Bourne shell script, try: ${JOB_NAME##*/})
所以你需要${JOB_NAME}
全部大写
shell 中的比较是
if [ "${JOB_NAME}"="xxxx" ]; then
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i hosts/dev playbook_deployRSProductPreProcessor.yml -v --extra-vars "RSProductPreProcessorVersion=${Number_Of_RSProductPreProcessor_Build_To_Deploy}"
fi
所以只有一个=
你的 Jenkins 可能使用不同的 shell 来挖掘,所以你可以通过在第一行添加一个 shebang 来强制 bash
#!/bin/bash
$JOB_NAME
是 Jenkins 生成的变量。无法覆盖。
您不能有一个名为 $Job_Name
的字符串参数。给它一个不同的名字,一个 Jenkins 没有保留的名字。
我为名为 "Job_Name" 的 jenkin 作业配置了一个字符串参数。
我想检查传递给 jenkins "execute shell command" 部分参数的值。
我当前的 shell 命令如下图所示。
Shell 命令:
if [ "${Job_Name}" == "RSProductPreprocessor" ]; then
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i hosts/dev playbook_deployRSProductPreProcessor.yml -v --extra-vars "RSProductPreProcessorVersion=${Number_Of_RSProductPreProcessor_Build_To_Deploy}"
fi
但是当我 运行 这份工作时,我收到如下回复。
+ '[' '' == RSProductPreprocessor ']'
Finished: SUCCESS
要使 if 条件正常工作,应该做什么。请指教
您有几件事需要解决
单击 shell 下的 link 查看可用的环境变量
这是我的一些
BUILD_NUMBER
The current build number, such as "153"
BUILD_ID
The current build id, such as "2005-08-22_23-59-59" (YYYY-MM-DD_hh-mm-ss)
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". (To strip off folder paths from a Bourne shell script, try: ${JOB_NAME##*/})
所以你需要${JOB_NAME}
全部大写
shell 中的比较是
if [ "${JOB_NAME}"="xxxx" ]; then
ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -i hosts/dev playbook_deployRSProductPreProcessor.yml -v --extra-vars "RSProductPreProcessorVersion=${Number_Of_RSProductPreProcessor_Build_To_Deploy}"
fi
所以只有一个=
你的 Jenkins 可能使用不同的 shell 来挖掘,所以你可以通过在第一行添加一个 shebang 来强制 bash
#!/bin/bash
$JOB_NAME
是 Jenkins 生成的变量。无法覆盖。
您不能有一个名为 $Job_Name
的字符串参数。给它一个不同的名字,一个 Jenkins 没有保留的名字。