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!
properties file in the maven project folder src/main/resources`. In pom. xml, add resources inside the building element and set filtering=true. filtering enables replacement variables from a project, or system to the resource files.
Get the pom properties using the properties plugin This will write all properties defined in the properties section of the pom into the version. properties file. But this has its downside. If you want a property to appear in the file, you will have to define it in the properties section.
The pom. xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.
From the Jenkins home page (i.e. the Dashboard of the Jenkins classic UI), click Manage Jenkins > Manage Credentials. Under Stores scoped to Jenkins on the right, click on Jenkins. Under System, click the Global credentials (unrestricted) link to access this default domain. Click Add Credentials on the left.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With