Top level docker agents can't be overridden - but you can use the
kubernetes plugin in Declarative (
https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/test/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/declarative.groovy
e.g.) which may be what you're looking for.

A.

On Thu, Sep 27, 2018 at 4:29 PM nirav <nira...@gmail.com> wrote:

> SO far I tried following but with all I keep hitting ‘Jenkins’ doesn’t
> have label ‘docker’
>
> Try 1 : Trying to override top-level agent. I get  ‘Jenkins’ doesn’t have
> label ‘docker’ and build hangs there
>
> pipeline {
>
>     agent {
>
>       docker {
>
>             image 'maven:3-alpine'
>
>             args '-v /Users/npatel/.m2:/root/.m2'
>
>         }
>
>     }
>
>     stages {
>
>         stage("Initialize") {
>
>              agent {
>
>       docker {
>
>             image 'maven:3.5.4-jdk-10'
>
>             args '-v /Users/npatel/.m2:/root/.m2'
>
>         }
>
>     }
>
>              steps{
>
>                 echo "buildId: ${env.BUILD_ID}"
>
>              }
>
>         }
>
>     }
>
>
> }
>
>
> Try 2 : Trying to override any agent. I still get  ‘Jenkins’ doesn’t have
> label ‘docker’ and build hangs there
>
> pipeline {
>
>     agent any
>
>     stages {
>
>         stage("Initialize") {
>
>              agent {
>
>       docker {
>
>             image 'maven:3.5.4-jdk-10'
>
>             args '-v /Users/npatel/.m2:/root/.m2'
>
>         }
>
>     }
>
>              steps{
>
>                 echo "buildId: ${env.BUILD_ID}"
>
>              }
>
>         }
>
>     }
>
>
> }
>
>
>
>
> On Thursday, September 27, 2018 at 1:01:25 PM UTC-7, nirav wrote:
>>
>> I am having trouble defining agents for my build pipeline. I need to use
>> 2 docker images as agents for entire pipe. first 4 steps uses one image and
>> last two steps uses another one. I don't want to repeat agent statement in
>> every stage.
>>
>> It was easy with scripted pipe. I defined all my images on top level and
>> then for each stage I just need to say container("${name of the image}")
>>      containers: [
>>         containerTemplate(name: 'maven', image: 'maven:3.5.4-jdk-10',
>> ttyEnabled: true, command: 'cat'),
>>         containerTemplate(name: 'docker', image: 'docker:18.03.1-ce',
>> ttyEnabled: true, command: 'cat'),
>>     ]
>>
>>
>> I see that declarative pipeline you can not define multiple agents at
>> pipeline level.
>>
>> Is there a way I can define agent in one stage and in all other stages i
>> refer them by label/name etc?
>>
>> ps - I don't want to do any setting under 'Manage Jenkins'.
>>
>> Thanks
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jenkinsci-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/5338401e-eb41-4c6a-818d-b3300dac3d14%40googlegroups.com
> <https://groups.google.com/d/msgid/jenkinsci-users/5338401e-eb41-4c6a-818d-b3300dac3d14%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAPbPdOYnU8zrsYy5vuN0YV4J3Mxueqi2ubaeXnANPzzhRBSOTA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to