Mateo
Mateo

Reputation: 1981

Running Jenkins parallel tasks sequentially

I'm writing a new Jenkins pipeline and have a set of steps that I would eventually like to run in parallel. But while I'm developing this pipeline I'd like to force it to run sequentially. I'm not seeing any way to specify the number of threads a parallel step uses or anything like that. Here is the basic code so far:

node('x') {
    stage('cleanup'){
        def cleanupScripts = [:]
        cleanupScripts[1] = { sh(script: "cleanup1.sh") }
        cleanupScripts[2] = { sh(script: "cleanup2.sh") }
        cleanupScripts[3] = { sh(script: "cleanup3.sh") }
        cleanupScripts[4] = { sh(script: "cleanup4.sh") }
        parallel cleanupScripts
    }
}

I'd like to be able to run those shell scripts sequentially without changing a lot of code.

Upvotes: 3

Views: 3496

Answers (2)

Joao  Vitorino
Joao Vitorino

Reputation: 3266

I don't know any way to run parallel steps in jenkins. You can run parallel jobs in the same node or in different nodes.

Running parallel jobs

parallel (
// job 1, 2 and 3 will be scheduled in parallel.
{ build("job1") },
{ build("job2") },
{ build("job3") }
)

You can make a job for each cleanup*.sh and call these jobs like above.

A more simple approach is use parallel command

Or simplest

clenaup1.sh &! clenaup3.sh &! clenaup4.sh &! ...

Upvotes: 0

cagatayo
cagatayo

Reputation: 146

Instead of parallel cleanupScripts you can use like this:

cleanupScripts.each{ key, value ->
    value()
}

Upvotes: 7

Related Questions