问题
Let's say I have a job A and also a slave configured. I want to run build 1 of Job A on master and build 2 of Job A on slave node. Is there an option to achieve that ?
OR
Is there a way where my job looks at master and if it already finds a build running, then start the next build on slave ?
回答1:
Are you intending to run in parallel or just alternate? (Not a good idea to run jobs on master; could configure a node to run on same host as "master".). Seems to be parallel and you have restricted to one executor each on master and agent (you can have more, in which case any advice may be moot).
Nevertheless, Jenkins queue job allocation to executors is "sticky"; it tries to run where last run, unless unavailable. This can lead to overloading in nodes. So the M,A,M,A pattern is unnatural.
There are plugins that might help: Least Load, Scoring Load Balancer, but maybe not.
Perhaps an approach would be to restrict your job using a label and have a post-build groovy step that moves the label to the other upon success for the next run or two labels and the job self-modifies the label to match the other.
来源:https://stackoverflow.com/questions/64130656/how-to-run-jenkins-build-alternatively-on-slave-nodes