简体   繁体   English

如何从Java应用程序获取Jenkins env变量?

[英]How to get Jenkins env variable from Java app?

I am running integration tests written in Java inside of a Jenkins pipeline. 我正在Jenkins管道内运行用Java编写的集成测试。

In my pipeline I am setting the appium.app.branch variable( env.'appium.app.branch' = branch ). 在我的管道中,我正在设置appium.app.branch变量( env.'appium.app.branch' = branch )。 Then I call 'mvn verify'. 然后,我将其称为“ MVN验证”。 The problem is that in my Java test code I can't get appium.app.branch value. 问题是在我的Java测试代码中,我无法获得appium.app.branch值。 System.getenv("appium.app.branch") call retutns null . System.getenv("appium.app.branch")调用retutns null

How to get the value? 如何获得价值?

Use withEnv() {} block. 使用withEnv() {}块。 Something like this should work 这样的事情应该工作

node {
  withEnv(["appium.app.branch=${branch}"]) {
    sh 'mvn verify'
  }
}

However I am not sure about the variable name, bash for example doesn't support variable names with dots. 但是我不确定变量名,例如bash不支持带点的变量名。 Try to use some alphanumeric + underscore name like APPIUM_APP_BRANCH 尝试使用一些字母数字+下划线名称,例如APPIUM_APP_BRANCH

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

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