java - Jenkins "execute shell command"段字符串参数的使用

标签 java shell deployment jenkins jobs

我为名为“Job_Name”的 jenkin 作业配置了一个字符串参数。

我想在 jenkins 的“执行 shell 命令”部分检查传递给参数的值。

我当前的 shell 命令如下所示。

enter image description here

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/

相关文章:

java - Kafka AdminClientConfig 忽略提供的配置

java.lang.ClassCastException : cannot be cast to RssLargeViewHolder

java - 从 mysql java 获取错误 "before start of result set"

linux - 如何使用 "find"在名称中包含空格的目录中搜索文件?

java permgen 对于 Linux 上的 swing 应用程序内存不足,但在 Windows 上则不然

linux - 如何在循环的 bash 脚本中引用 "next"命令行参数?

linux - 用于运行命令的 Bash 脚本

spring - 将 spring mvc 项目部署到 tomcat 时,有什么方法可以自动重写 URL?

tomcat - 从 Intellij 在 tomcat 中将 Web 应用程序部署为 ROOT.war 应用程序

ruby-on-rails - 部署到 heroku 时出错:rake Assets :预编译 PG::ConnectionBad:无法连接到服务器:连接被拒绝