On Jenkins, Maven ignores the environment variables MAVEN_OPTS and MAVEN_ARGS that I set in the same pipeline. Here the code I use:
pipeline {
agent {
docker {
image 'iubar-maven-alpine'
label 'docker'
args '-v ${HOME}/.m2:/home/jenkins/.m2:rw,z'
}
}
environment {
MAVEN_ARGS = '--show-version --batch-mode'
MAVEN_OPTS = '-Djava.awt.headless=true'
}
stages {
stage ('Build') {
steps {
sh 'mvn clean compile'
}
}
...
so to solve the problem I need to write :
...
stage ('Build') {
steps {
sh 'mvn $MAVEN_ARGS $MAVEN_OPTS clean compile'
}
}
...
What are the causes of this behavior ? And is there any better solutions ?
1