Problem with docker agent (declarative syntax)

2,183 views
Skip to first unread message

Bartłomiej Kruczyk

unread,
Feb 9, 2017, 7:38:22 AM2/9/17
to Jenkins Users
Hi, I have problem with setting docker agent type for my pipeline.

Although something like this works:


agent {
    docker 'myimage'

}


This does not:


agent {
    docker {
        image: 'myimage'

        registry: 'localhost:5000'

    }
}


As I'm getting error:


org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 3: Expected to find someKey "someValue" @ line 3, column 12.
       docker {
              ^

WorkflowScript: 3: Missing required parameter for agent type "docker": image @ line 3, column 5.
       docker {
       ^

2 errors

	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1073)
	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:591)
	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:569)
	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:546)
	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:67)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:429)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:392)
	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:221)
	at hudson.model.ResourceController.execute(ResourceController.java:98)
	at hudson.model.Executor.run(Executor.java:404)
Finished: FAILURE

How I make it work?

R. Tyler Croy

unread,
Feb 10, 2017, 4:39:49 AM2/10/17
to jenkins...@googlegroups.com
(replies inline)

On Thu, 09 Feb 2017, Bart??omiej Kruczyk wrote:

> Hi, I have problem with setting docker agent type for my pipeline.
>
> Although something like this works:
>
>
> agent {
> docker 'myimage'
>
> }
>
>
> This does not:
>
>
> agent {
> docker {
> image: 'myimage'
>
> registry: 'localhost:5000'
>
> }
> }


As far as I am aware, there is no supported "registry" value inside that
`docker` block.


See also https://jenkins.io/doc/book/pipeline/syntax/#agent



- R. Tyler Croy

------------------------------------------------------
Code: <https://github.com/rtyler>
Chatter: <https://twitter.com/agentdero>
xmpp: rty...@jabber.org

% gpg --keyserver keys.gnupg.net --recv-key 1426C7DC3F51E16F
------------------------------------------------------
signature.asc

Christopher Orr

unread,
Feb 10, 2017, 6:36:19 AM2/10/17
to jenkins...@googlegroups.com
Hi there,

On Thu, 9 Feb 2017, at 13:38, Bartłomiej Kruczyk wrote:
agent {
    docker {
        image: 'myimage'

        registry: 'localhost:5000'

    }
}


A couple of points:

1. The syntax documentation is wrong at the moment: you should not add a colon after the key
2. The key you're looking for is "registryUrl"


For example:
agent {
  docker {
    image 'foo'
    registryUrl 'registry.example.com'
  }
}

Regards,
Chris


Christopher Orr

unread,
Feb 10, 2017, 7:02:33 AM2/10/17
to jenkins...@googlegroups.com
Quick correction:
The 'registryUrl' value needs to be a proper URI, e.g. 'https://registry.hub.docker.com'

-Chris

Bartłomiej Kruczyk

unread,
Feb 10, 2017, 7:20:03 AM2/10/17
to Jenkins Users
That worked like a charm. I had found issue https://issues.jenkins-ci.org/browse/JENKINS-39684, and source file you are referring but I didn't known what declarative syntax expression it should be.
Thank you!

Bartłomiej Kruczyk

unread,
Feb 10, 2017, 7:21:48 AM2/10/17
to Jenkins Users
Thanks for your reply, it's not yet documented but I found issue which asserted that this feature is implemented.
Christopher's solution works.
Reply all
Reply to author
Forward
0 new messages