简体   繁体   中英

Multijob DSL - How to “label” each phaseJob with specific node/cloud/agent in Job DSL plugin?

I'm trying to label each phaseJob in multiJob DSL plugin with specific node (in my case it's docker-cloud created with Docker Plugin).

Instead of labeling each phaseJob with specific node (docker-cloud) it labels every job with latest mentioned docker-cloud/node label.

I've tried the following example DSL configuration:

multiJob('example-multiple-job') {
    steps {
        phase('First') {
            phaseJob('JobA'){
                label('docker-a')
                shell('echo Hello World JobA!') 
                shell('sleep 1m')
            }
            phaseJob('JobB'){
                label('docker-b')
                shell('echo Hello World JobB!')
                shell('sleep 1m')
            }
        }
    }
}

So, it labels whole multiJob with docker-b label (as it is the latest one)

In addition to that, I've given a try to the following syntax:

multiJob('example-multiple-job') {
    steps {
        phase('First') {
            job('JobA'){
                label('main-docker-a')
                shell('echo Hello World JobA!') //
                shell('sleep 1m')
            }
            job('JobB'){
                label('main-docker-b')
                shell('echo Hello World JobB!')
                shell('sleep 1m')
            }
        }
    }
}

It creates jobs with expected label, but they are not included in Multiple job project.

My expectentions are:

Each following phaseJob is runnign on it's own docker-cloud node and automatically included in Multiple job project automatically as it done without labeling.

After some time reading Job DSL docs I came with solution. Actually, just had to read it more attentive:)

Here is working example of how several jobs with it's own labeled node/docker-cloud could be executed in parallel with, in docker containers

job('JobA') {
    label('docker-a')
    steps {
        shell('echo Hello World Job-A!')
        shell('sleep 1m')
    }
}

job('JobB') {
    label('docker-b')
    steps {
        shell('echo Hello World Job-B!')
        shell('sleep 1m')
    }
}

multiJob('example-multiple-job') {
    steps {
        phase('First') {
            phaseJob('JobA')
            phaseJob('JobB')
        }
    }
}

As I unserstood, jobs and everythign else is created separatly, but multipleJob() directive just helps to manage them all with additional behavior and features.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM