【Jenkins】Pipelineでxmlをパース
pom.xmlで管理している特定のモジュールに対して、SNAPSHOTを付けて回りたかったときのメモ
極力jenkinsのプラグインは使わない
できたもの
import groovy.xml.StreamingMarkupBuilder import groovy.xml.XmlUtil pipeline { agent any stages { stage('clean') { steps{ cleanWs() } } stage('Git checkout') { steps { git credentialsId: 'xxxxxx', url: 'https://github.com/xxxxxxx.git', branch: "develop" } } stage('xmledit') { steps { script { def xmlFile = readFile(file: 'pom.xml') def project = xmlRead(xmlFile) for (dep in project.dependencyManagement.dependencies.dependency) { def idtext = dep.artifactId.text() if ("〇〇" == idtext){ def ver = dep.version.text() dep.version = ver + "-SNAPSHOT" } } project = new XmlSlurper(false,false).parseText(XmlUtil.serialize(project)) EDIT_XMLFILE = XmlUtil.serialize(project) } } } stage('xmlwtire') { steps { script { xmlWtire(EDIT_XMLFILE) } } } } post { failure { echo "========A execution failed========" } } } @NonCPS def xmlWtire(String xmltext) { writeFile(file: 'pom.xml', text: xmltext) } @NonCPS def xmlRead(String xmlFile) { def project = new XmlSlurper(false,false).parseText(xmlFile) return project }