Reputation: 101
Let's say I have a custom property in my pom.xml set like this:
<properties>
<app>com.myProject.app</app>
</properties>
How can I access it in my jenkinsfile?
This:
def pom = readMavenPom file: 'pom.xml'
def appName = pom.app
returns
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: unclassified field org.apache.maven.model.Model app
Thanks in advance!
Upvotes: 8
Views: 14625
Reputation: 21
jenkins pipeline add this stage. more see
stage('info')
{
steps
{
script
{
def version = sh script: 'mvn help:evaluate -Dexpression=project.version -q -DforceStdout', returnStdout: true
def artifactId = sh script: 'mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout', returnStdout: true
}
}
}
Upvotes: 1
Reputation: 386
try this: IMAGE = readMavenPom().getArtifactId() VERSION = readMavenPom().getVersion()
Upvotes: 0
Reputation: 99
In pipeline style, inside Jenkinsfile you can access the value as follows
pipeline {
environment {
POM_APP = readMavenPom().getProperties().getProperty('app')
}
stages{
stage('app stage'){
steps{
script{
sh """
echo ${POM_APP}
"""
}
}
}
}
Upvotes: 6
Reputation: 841
I know two approaches:
properties-maven-plugin
to write the properties to a file. Use readProperties
in the Jenkinsfile to read the properties.pom = readMavenPom 'path/to/pom.xml'
. Afterwards, access the property like this: pom.properties['com.myProject.app']
.I like approach 2 much better: No extra plugin configuration in the POM, no file written, less sequencing constraints, less fragilities.
Upvotes: 9