我正在使用Jenkins运行Maven目标。
命令1 -
mvn test
(运行默认配置文件)(创建以下命令2使用的几个输出文件夹)
命令2 -
mvn test -P secondMavenProfileName
(pom.xml中的第二个maven配置文件,需要处理由Command 1创建的输出文件)。
如何在单个Jenkins作业中运行这两个命令?要求是命令1的输出文件必须在命令2启动时生成,并且命令2应该能够对它们进行操作。
在Jenkins管道中实现这一点的正确方法是什么?
当我简单地在Jenkins管道中一个接一个地添加上述两个命令时,作业失败,因为第一个命令的输出文件在命令2启动时没有生成/写入。
管道脚本:
pipeline {
agent any
options {
timestamps()
}
stages {
stage('Create file and wait') {
steps {
bat 'mvn -help > mvn.txt'
bat '@ping -n 10 localhost > nul'
}
}
stage('Use file') {
steps {
bat 'type mvn.txt'
}
}
}
}
控制台输出摘录:
...
[Pipeline] stage
[Pipeline] { (Create file and wait)
[Pipeline] bat
00:52:23
00:52:23 C:UsersjenkinsAppDataLocalJenkins.jenkinsworkspaceSO-68673343 Pipeline stage 1 output used in stage 2>mvn -help 1>mvn.txt
[Pipeline] bat
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Use file)
[Pipeline] bat
00:52:33
00:52:33 C:UsersjenkinsAppDataLocalJenkins.jenkinsworkspaceSO-68673343 Pipeline stage 1 output used in stage 2>type mvn.txt
00:52:33
00:52:33 usage: mvn [options] [<goal(s)>] [<phase(s)>]
00:52:33
00:52:33 Options:
00:52:33 -am,--also-make If project list is specified, also
00:52:33 build projects required by the
00:52:33 list
... ... ...
00:52:33 -X,--debug Produce execution debug output
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // timestamps
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS