Hozuki Ferrari
Hozuki Ferrari

Reputation: 305

How to get Jenkins env variable from Java app?

I am running integration tests written in Java inside of a Jenkins pipeline.

In my pipeline I am setting the appium.app.branch variable(env.'appium.app.branch' = branch). Then I call 'mvn verify'. The problem is that in my Java test code I can't get appium.app.branch value. System.getenv("appium.app.branch") call retutns null.

How to get the value?

Upvotes: 0

Views: 417

Answers (1)

Vitalii Vitrenko
Vitalii Vitrenko

Reputation: 10395

Use withEnv() {} block. 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. Try to use some alphanumeric + underscore name like APPIUM_APP_BRANCH

Upvotes: 1

Related Questions