简体   繁体   English

Jenkins + Maven-如何在发布前执行Shell脚本:执行清理项目

[英]Jenkins + Maven - How to execute shell script before release:perform cleans the project

I have a Maven project that generates a zip file with maven-assembly-plugin on mvn package 我有一个Maven项目,该项目在mvn包上使用maven-assembly-plugin生成一个zip文件

MyProy
|--pom
|--src/...
|--target
     |---MyProy-something-1.0.0-SNAPSHOT-zip (contains /1.0.0-SNAPSHOT/...)

I created a Jenkins job and configured a shell script execution as a post step. 我创建了一个Jenkins作业,并在后续步骤中配置了Shell脚本执行。 This script copies the zip to a folder (/something) and unzips it 该脚本将zip复制到文件夹(/某物)并解压缩

|-/something
     |---1.0.0-SNAPSHOT
             |---...

This works fine for builds. 这适用于构建。 However I want to do the same when I launch a release. 但是,当我发布一个版本时,我想做同样的事情。 I installed Jenkins release plugin and in "configure release build" I added this tasks: 我安装了Jenkins发布插件,并在“配置发布版本”中添加了以下任务:

  1. Before release build -> Maven task mvn release:prepare 发行前构建-> Maven任务mvn release:prepare
  2. After successful release build -> Maven task mvn release:perform 成功发布后-> Maven任务mvn release:perform
  3. After successful release build -> Execute shell script - Copy zip and unzip. 成功发布后,构建->执行shell脚本-复制zip和解压缩。

I see the mvn release:perform execute correctly, for instance with version 1.0.0 but the problem is that when the script (3.) is launched it applies to the next development version (1.0.1-SNAPSHOT) instead of the release version (1.0.0). 我看到mvn release:perform正确执行,例如使用1.0.0版,但是问题是启动脚本(3.)时,它适用于下一个开发版本(1.0.1-SNAPSHOT),而不是发行版(1.0.0)。

This is how I managed to work around the problem: 这是我设法解决此问题的方法:

  1. Before release build 发布前构建

    1. mvn release:prepare mvn发布:准备
  2. After successful release build 成功发布后

    1. mvn release:perform mvn版本:执行
    2. mvc scm:checkout -DscmVersion=${releaseVersion} -DscmVersionType=tag mvc scm:checkout -DscmVersion = $ {releaseVersion} -DscmVersionType = tag
    3. -f ${WORKSPACE}/target/checkout clean install -f $ {WORKSPACE} / target / checkout全新安装
    4. Execute shell script with copy and unzip 使用复制和解压缩执行Shell脚本

To sum up, after the release:perform I checkout the brand new tag, execute a clean install in the location of the downloaded tag and finally I execute the script that copies the zip and unzipes it. 总而言之,在release:perform之后,我签出全新的标签,在下载的标签的位置执行全新安装,最后执行复制zip并将其解压缩的脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM