2
votes

I'm new to Jenkins and I'm trying to setup a project which will use few build executors. The flow shall be as follows:

  • two build executors with webservice label return their IP addresses and wait for the third build executor to finish its job
  • third build executor with tester label collects those IP addresses and performs some long running job (e.x. sends HTTP requests to the webservices deployed on those two agents)

How to achieve such behavior in Jenkins?

I've found that when an build executor finishes its job it is immediately released and I don't know how to make it wait for other build executors to finish their jobs.

Edit:

I forgot to mention that I want the build executors with the webservice label to be reserved (not available for other jobs) till the build executor with the tester label will finish its long-running job.

Also all these build executors should be on separate slaves each. That means each slave has only one build executor.

3
The question wil be easier to understand if you rephrase it using Jenkins terminology (job/project, slave) instead of setting up a "build" that uses "agents". - Alex O
Sorry. As I said, I'm new to Jenkins. When I say "agent" I mean build executor (I don't know yet if a build executor and a slave means the the same thing). And I guess "build" shall be changed to "project". Please, correct me if I'm wrong. - Mateusz
Thanks, that's more clear : ) A slave can hold multiple executors (image it as one machine with multiple CPUs for running tasks simultaneously). - Alex O

3 Answers

3
votes

I've finally managed to do this using Pipeline and below script:

node('webservice') {
    def firstHostname = getHostname()
    node('webservice') {
        def secondHostname = getHostname()
        node('tester') {
            println 'Running tests against ' + firstHostname + ' and ' + secondHostname
            // ...
        }
    }
}

def getHostname() {
    sh 'hostname > output'
    readFile('output').trim()
}

It acquires two build executors with webservice label. I'm getting their hostnames (I'm using them instead of the IP addresses) and pass them to the build executor with a tester label. Finally the tester runs some long-running tests.

Those two webservice build executors are blocked till the tester finishes its job, and no other project may use them during that time.

0
votes

As Alex O mentioned, you can configure the master and slave relationship between the projects /executors inside the Jenkins projects /executors. There is option for that, "Build Triggers" -> Build after other projects are built

or use plugin to achieve it https://wiki.jenkins-ci.org/display/JENKINS/Parameterized+Trigger+Plugin

or https://wiki.jenkins-ci.org/display/JENKINS/Join+Plugin

0
votes

What you actually want is probably that your job uses three slaves at the same time.

Re-thinking the setup in that way, it won't be necessary to consider the collection of IPs and the subsequent usage of the slaves as three different steps that must be aligned in some way.

Unfortunately, Jenkins does not support using multiple slaves for one build out-of-the box, but it will be possible to achieve what you want e.g. using the Multijob plugin and the Join plugin that Aaron mentioned already.

See also this question for information on how to use two slaves at the same time.