Jenkins Workflow:如何并行执行集成测试
Jenkins Workflow: How to execute integration tests in parallel
大家好,我一直在处理这个问题,但我找不到解决方案,因为每次都在名为 MyProject@1,2,3,4 的新目录中进行集成测试 运行...
我已经声明我希望他们在特定目录中 运行 但这无济于事。这是我的代码示例。
parallel( FirstSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 0 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=FirstSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/FirstSuite'
}
}
},
SecondSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 20 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=SecondSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/SecondSuite'
}
}
},
ThirdSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 40 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=ThirdSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/ThirdSuite'
}
}
},
FourthSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 60 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=FourthSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/FourthSuite'
}
}
},
FifthSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 80 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=FifthSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/FifthSuite'
}
}
},
SextSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 100 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=SextSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/SextSuite'
}
}
},
SeventhSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 120 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=SeventhSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/SeventhSuite'
}
}
},
EighthSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 140 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=EighthSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/EighthSuite'
}
}
},)
但我仍然在 maven 中收到 pom 不可读的错误,并且该目录丢失,因为这个 ws 命令没有帮助。我的集成测试在 MyProject@2、@3、@4 等中执行...
[FirstSuite] + mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=FirstSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/FirstSuite
[FirstSuite] Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=384m; support was removed in 8.0
[FirstSuite] [INFO] Scanning for projects...
[FirstSuite] [ERROR] The build could not read 1 project -> [Help 1]
[PmClientTestsuite] [ERROR]
[FirstSuite] [ERROR] The project (/opt/.jenkins/workspace/MyProject@16/java/pom.xml) has 1 error
[FirstSuite] [ERROR] Non-readable POM /opt/.jenkins/workspace/MyProject@16/java/pom.xml: /opt/.jenkins/workspace/MyProject@16/java/pom.xml (Datei oder Verzeichnis nicht gefunden)
[FirstSuite] [ERROR]
[FirstSuite] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[FirstSuite] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[FirstSuite] [ERROR]
[FirstSuite] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[FirstSuite] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
这是因为您使用了ws步骤。而不是使用 dir,它不检查路径的唯一性。
来自 Jenkins Pipeline Snippet Generator 关于 ws 的帮助提示:
If concurrent builds ask for the same workspace, a directory with a suffix such as @2 may be locked instead. Currently there is no option to wait to lock the exact directory requested; if you need to enforce that behavior, you can either fail (error) when pwd indicates that you got a different directory, or you may enforce serial execution of this part of the build by some other means such as stage name: '…', concurrency: 1.
If you do not care about locking, just use the dir step to change current directory.
此外,如果您的实际意图是在同一节点上执行所有执行流,我建议将 node 移出 parallel。像这样:
node('master') {
dir('/opt/.jenkins/workspace/MyProject') {
parallel FirstSuite: { ... },
SecondSuite: { ... },
<... other suites ... >
}
}
大家好,我一直在处理这个问题,但我找不到解决方案,因为每次都在名为 MyProject@1,2,3,4 的新目录中进行集成测试 运行...
我已经声明我希望他们在特定目录中 运行 但这无济于事。这是我的代码示例。
parallel( FirstSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 0 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=FirstSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/FirstSuite'
}
}
},
SecondSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 20 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=SecondSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/SecondSuite'
}
}
},
ThirdSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 40 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=ThirdSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/ThirdSuite'
}
}
},
FourthSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 60 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=FourthSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/FourthSuite'
}
}
},
FifthSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 80 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=FifthSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/FifthSuite'
}
}
},
SextSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 100 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=SextSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/SextSuite'
}
}
},
SeventhSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 120 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=SeventhSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/SeventhSuite'
}
}
},
EighthSuite: {
node('master') {
ws('/opt/.jenkins/workspace/MyProject') {
sh 'sleep 140 && mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=EighthSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/log/EighthSuite'
}
}
},)
但我仍然在 maven 中收到 pom 不可读的错误,并且该目录丢失,因为这个 ws 命令没有帮助。我的集成测试在 MyProject@2、@3、@4 等中执行...
[FirstSuite] + mvn -s settings.xml -f java/pom.xml integration-test -P dev -Dmaven.repo.local=.repository -Dit.test=FirstSuite -Djava.io.tmpdir=java/target -Dlog.dir=java/target/FirstSuite
[FirstSuite] Java HotSpot(TM) Server VM warning: ignoring option MaxPermSize=384m; support was removed in 8.0
[FirstSuite] [INFO] Scanning for projects...
[FirstSuite] [ERROR] The build could not read 1 project -> [Help 1]
[PmClientTestsuite] [ERROR]
[FirstSuite] [ERROR] The project (/opt/.jenkins/workspace/MyProject@16/java/pom.xml) has 1 error
[FirstSuite] [ERROR] Non-readable POM /opt/.jenkins/workspace/MyProject@16/java/pom.xml: /opt/.jenkins/workspace/MyProject@16/java/pom.xml (Datei oder Verzeichnis nicht gefunden)
[FirstSuite] [ERROR]
[FirstSuite] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[FirstSuite] [ERROR] Re-run Maven using the -X switch to enable full debug logging.
[FirstSuite] [ERROR]
[FirstSuite] [ERROR] For more information about the errors and possible solutions, please read the following articles:
[FirstSuite] [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
这是因为您使用了ws步骤。而不是使用 dir,它不检查路径的唯一性。
来自 Jenkins Pipeline Snippet Generator 关于 ws 的帮助提示:
If concurrent builds ask for the same workspace, a directory with a suffix such as @2 may be locked instead. Currently there is no option to wait to lock the exact directory requested; if you need to enforce that behavior, you can either fail (error) when pwd indicates that you got a different directory, or you may enforce serial execution of this part of the build by some other means such as stage name: '…', concurrency: 1.
If you do not care about locking, just use the dir step to change current directory.
此外,如果您的实际意图是在同一节点上执行所有执行流,我建议将 node 移出 parallel。像这样:
node('master') {
dir('/opt/.jenkins/workspace/MyProject') {
parallel FirstSuite: { ... },
SecondSuite: { ... },
<... other suites ... >
}
}