Reputation: 239
I'm trying to convert a free-style job to pipeline code. following are the MAVEN_OPTS got declared along with maven goals under "Invoke Artifactory Maven 3" in job.
Maven Goals: clean install
MAVEN_OPTS: -Xmx2048m
-Xms512m
-XX:PermSize=256m
-XX:MaxPermSize=1024m
-Denv.build-timestamp=${BUILD_TIMESTAMP}
-Denv.build-job=${JOB_NAME}
-Denv.build-number=${BUILD_NUMBER}
-Denv.build-url=${BUILD_URL}
-Denv.git-commit=${GIT_COMMIT}
-Denv.git-branch=${GIT_BRANCH}
My trial in pipeline:
node('node1') {
def javaHome = tool name: 'JDK 1.8', type: 'hudson.model.JDK'
def mvnHome = tool name: 'M3', type: 'hudson.tasks.Maven$MavenInstallation'
sh "$mvnHome/bin/mvn -f pom.xml clean install -U -Dmaven.repo.local=$WORKSPACE/.m2/repository -Xmx2048m -Xms512m -XX:PermSize=256m -XX:MaxPermSize=1024m -Dtimestamp=${BUILD_TIMESTAMP} ..."
}
Error:
Could not find metadata org.apache.maven.plugins/maven-metadata.xml in local
I'm sure that I'm passing MAVEN_OPTS in a wrong way. Can someone guide me the right systax to declare MAVEN_OPTS in Pipeline
Upvotes: 5
Views: 11944
Reputation: 239
You can set the mavenOpts
in the withMaven
call in a pipeline stage
:
node('node1') {
stage ('MavenGoals') {
withMaven(jdk: 'JDK 1.8',
maven: 'M3',
mavenLocalRepo: '$WORKSPACE/.m2/repository',
mavenOpts: '-Xmx2048m -Xms512m -XX:PermSize=256m ....') {
sh 'mvn clean install'
}
}
}
Upvotes: 9
Reputation: 318
Set environment variable MAVEN_OPTS and it will work.
pipeline {
agent any
tools {
jdk 'JDK 1.8'
maven 'M3'
}
environment {
MAVEN_OPTS = ' -Denv.build-timestamp=${BUILD_TIMESTAMP} ...'
}
stage('Example') {
steps {
sh 'mvn clean install'
}
}
}
Upvotes: 8