jenkins读取pom.xml

需求

在jenkins pipeline中,需要获取pom.xml中一些信息

实现方法

前提:

  1. jenkins安装Pipeline Utility Steps插件
  2. 在readMavenPom出错时,要在scriptApproval允许Approvals

安装Pipeline Utility Steps插件

《jenkins读取pom.xml》 j20.png
《jenkins读取pom.xml》 j20-1.png

使用readMavenPom报错处理

《jenkins读取pom.xml》 j21-0.png
《jenkins读取pom.xml》 j21-1.png
《jenkins读取pom.xml》 j21-2.png

使用示例:

stage('Publish') {
 def pom = readMavenPom file: 'pom.xml'
 nexusPublisher nexusInstanceId: 'nexus2', \
  nexusRepositoryId: 'releases', \
  packages: [[$class: 'MavenPackage', \
  mavenAssetList: [[classifier: '', extension: '', \
  filePath: "target/${pom.artifactId}-${pom.version}.${pom.packaging}"]], \
  mavenCoordinate: [artifactId: "${pom.artifactId}", \
  groupId: "${pom.groupId}", \
  packaging: "${pom.packaging}", \
  version: "${pom.version}"]]]
}

参考

  1. readMavenPom: Read a maven project file
  2. readMavenPom可以获取的信息
  3. Jenkins Publish Using Maven Coordinates from the pom.xml
  4. Cannot use readMavenPom in Jenkinsfile要安装 pipeline-utility-steps 插件
    原文作者:郑石马
    原文地址: https://www.jianshu.com/p/29403ecf7fc2
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞