Created
April 26, 2018 16:08
-
-
Save adambarreiro/f4b823e7e344314a902f1535dbfede18 to your computer and use it in GitHub Desktop.
How to obtain a POM property using a Jenkins pipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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] : '' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wonder if we could have a solution using https://jenkins.io/doc/pipeline/steps/pipeline-utility-steps/#code-readmavenpom-code-read-a-maven-project-file instead of Regexes 🤔