问题
I am trying to setup various Jenkins pipelines whose last stage is always to run some acceptance tests. To cut a long story short, acceptance tests and test data (much of which is shared) for all products are checked into the same repository which is about 0.5 GB in size. It therefore seemed best to have a separate job for the acceptance tests and trigger it with a "build" step from each pipeline with the appropriate arguments to run the relevant tests. (It is also sometimes useful to rerun these tests without rebuilding the product)
stage('AcceptanceTest') {
steps {
build job: 'run-tests', parameters: ..., wait: true
}
}
So far I have seen that I can either:
- trigger the job as normal. But this uses an extra agent/executor, there doesn't seem to be a way to tell it to reuse the one from the build (main pipeline). Both pipelines start with "agent { label 'master' }" but that seems to mean "allocate a new agent on a node matching master".
- trigger the job with the "wait: false" argument. This doesn't block an executor but it does mean I can't report the results of the tests in the main pipeline. It gives the impression that the test stage has always succeeded.
Is there a better way?
回答1:
I seem to have solved this, by adding "agent none" at the top of my main pipeline and moving "agent { label 'master' }" into the build stage. I can then leave my 'AcceptanceTest' stage without an agent and define it in the 'run-tests' job as before. I was under the impression from the docs that if you put agents in stages then all stages needed to have one, but it seems not to be the case. Which is lucky for this usecase...
回答2:
I don't think that there's another way for declarative pipeline.
On the other hand for scripted pipeline you could execute this outside of node {}
and it would just hold onto one executor on master releasing the one on slave.
stage("some") {
build job: 'test'
node {
...
回答3:
Related question: Jenkis - Trigger another pipeline job in same machine - without creating new "Executor"
来源:https://stackoverflow.com/questions/55099269/jenkins-pipeline-how-to-trigger-another-job-and-wait-for-it-without-using-an-ex