1

我遇到了与此处提到的类似的问题: Jenkinsfile Declarative Pipeline defined dynamic env vars

我正在尝试通过 jenkinsfile 部署应用程序。为此,我必须在 Jenkins 的部署阶段运行此命令(如果我对值进行硬编码,那么它可以正常工作):

xldDeploy serverCredentials: 'usernam', environmentId: 'Environments/SysTest1/SysTest1_1', packageId: 'Applications/Testapp/testapp_1.0.4.5.Build39_TAG-test'

“testapp_1.0.4.5.Build39_TAG-test”在运行时生成。可以通过连接"${TagVersion}.Build${env.BUILD_NUMBER}_${ComponentTagName}" 我在 jenkins 管道中尝试的以下代码来创建它:

stage('Deploy') {  
   node('noibuild01') {
    if ("${env.Build_WildflyCPECommon}" == 'true') {
    echo "${TagVersion}"
    echo "${ComponentTagName}"
    echo "${env.BUILD_NUMBER}"
    script {
                    env.buildNumber = "${TagVersion}.Build${env.BUILD_NUMBER}_${ComponentTagName}"
                    env.packageid = "'Applications/Testapp/${env.buildNumber}'"
                }
    echo "${env.buildNumber}"
    echo "${env.packageid}"

    xldDeploy serverCredentials: 'nex8voo', environmentId: 'Environments/SysTest1/SysTest1_1', packageId: "${env.packageid}"
    }
    }
  }

我检查了输出,它显示正确:

echo "${env.buildNumber}" giving
testapp_1.0.4.5.Build39_TAG-test
echo "${env.packageid}" giving 
'Applications/Testapp/testapp_1.0.4.5.Build39_TAG-test'

但是xldDeploy serverCredentials: 'username', environmentId: 'Environments/SysTest1/SysTest1_1', packageId: "${env.packageid}" 作为 [/repository/ci/'Applications/Testapp/testapp_1.0.4.5.Build39_TAG-test']: Repository entity ['Applications/Testapp/testapp_1.0.4.5.Build39_TAG-test'] not found

我觉得我不能用packageId: "${env.packageid}"

有什么我可以尝试的吗?也许是 Groovy 或 Python 代码?

4

1 回答 1

4

您的packageid环境变量未正确分配连接字符串。您在字符串插值引号内有文字引号。您应该将其更改为:

env.packageid = "Applications/Testapp/${env.buildNumber}"

只插入字符串,这是您想要的功能。

此外,您不需要在方法参数的空字符串中插入环境变量,因此您的方法调用可以清理为:

xldDeploy serverCredentials: 'nex8voo', environmentId: 'Environments/SysTest1/SysTest1_1', packageId: env.packageid
于 2019-05-13T20:35:10.957 回答