【问题标题】:Usage of string parameter in "execute shell command" section of JenkinsJenkins的“执行shell命令”部分中字符串参数的使用
【发布时间】:2015-03-17 08:31:42
【问题描述】:

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

我想检查 jenkins 的“执行 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 条件正常工作。请指教。

【问题讨论】:

    标签: java shell deployment jenkins jobs


    【解决方案1】:

    你有几件事要解决

    单击您的 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
    

    【讨论】:

      【解决方案2】:

      $JOB_NAME 是 Jenkins 生成的变量。它不能被覆盖。

      您不能有一个名为$Job_Name 的字符串参数。给它一个不同的名字,一个不是 Jenkins 保留的名字。

      【讨论】:

        猜你喜欢
        • 2016-08-08
        • 1970-01-01
        • 1970-01-01
        • 2014-01-11
        • 2020-05-19
        • 2017-12-10
        • 2019-03-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多