我为名为“Job_Name”的 jenkin 作业配置了一个字符串参数。
我想在 jenkins 的“执行 shell 命令”部分检查传递给参数的值。
我当前的 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 下的链接以查看可用的环境变量
这是我的一部分
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
关于java - Jenkins "execute shell command"段字符串参数的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29094408/