简体   繁体   English

如何在Jenkins Groovy DSL中获得动态属性

[英]How to get a dynamic property in Jenkins Groovy DSL

Please read the comments to understand the problem. 请阅读评论以了解问题所在。

job(buildV2PerfTest) {
    displayName('Performance Test')
    steps {

        //I am loading a value into a properties file using the shell command. The name of the variable is callbackUrl
        shell('echo "callbackUrl=http://`curl http://169.254.169.254/latest/meta-data/public-hostname`:8080" > env.properties')

        //then I add the propeties file to Jenkins properties
        environmentVariables {
            propertiesFile('env.properties')
        }
        maven {
            goals('-P performance test')
            //I want to pass to maven a loaded property here
            property('callbackUrl', "${callbackUrl}")
        }
    }
}

The problem is that when I compile this code it says that the property does not exists. 问题是,当我编译此代码时,它说该属性不存在。 Indeed. 确实。 It will exist when I trigger the job. 当我触发工作时它将存在。 I want to know how to reference dynamic properties. 我想知道如何引用动态属性。

PS The documentation tells how to load the variables, but fails in explain how to access them PS该文档介绍了如何加载变量,但未能解释如何访问变量

解决方案是:

property('callbackUrl', "\$callbackUrl")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM