Skip to content

Instantly share code, notes, and snippets.

@adambarreiro
Created April 26, 2018 16:08
Show Gist options
  • Save adambarreiro/f4b823e7e344314a902f1535dbfede18 to your computer and use it in GitHub Desktop.
Save adambarreiro/f4b823e7e344314a902f1535dbfede18 to your computer and use it in GitHub Desktop.
How to obtain a POM property using a Jenkins pipeline
/**
* Obtains a specific property given as a maven-help plugin expression.
* For example 'project.artifactId'
*
* @param {String} args.mavenId - Maven installation ID
* @param {String} args.expression - Expression to obtain the property
* @return The POM property
*/
public String getPropertyFromPom(Map args) {
withMaven([maven: args.mavenId]) {
String rawMvnResult = sh(script: "mvn org.apache.maven.plugins:maven-help-plugin:3.0.0:evaluate -Dexpression=${args.expression} 2> /dev/null", returnStdout: true)
def matcher = rawMvnResult =~ /\[INFO\]\ *\n([^\[].*)\n/
return matcher.find() ? matcher[0][1] : ''
}
}
@RecuencoJones
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment