Interpolating variables in agent's docker parameter

37 views
Skip to first unread message

Bartłomiej Sacharski

unread,
May 17, 2017, 3:03:25 PM5/17/17
to Jenkins Users
Hello.

I'm trying to mount specific directory to a stage-only agent that will use docker in a declarative pipeline.
It looks like this:
agent {
  docker {
    image "myimage:latest"
    args "-v ${WORKSPACE}/out:/var/www/api/out"
  }
}

However, this results in No such property: WORKSPACE. When I'm using env.WORKSPACE it is interpolated to null (also resulting in error).
Does that mean that interpolation is only available for steps, or is there another trick (without resorting to scripted pipeline) to interpolate string properly in this case?

R. Tyler Croy

unread,
May 17, 2017, 3:23:44 PM5/17/17
to jenkins...@googlegroups.com
(replies inline)

On Wed, 17 May 2017, Bart??omiej Sacharski wrote:

> Hello.
>
> I'm trying to mount specific directory to a stage-only agent that will use
> docker in a declarative pipeline.
> It looks like this:
>
> > agent {
> > docker {
> > image "myimage:latest"
> > args "-v ${WORKSPACE}/out:/var/www/api/out"
> > }
> > }
> >
>
> However, this results in *No such property: WORKSPACE*. When I'm using
> *env.WORKSPACE* it is interpolated to *null* (also resulting in error).
> Does that mean that interpolation is only available for steps, or is there
> another trick (without resorting to scripted pipeline) to interpolate
> string properly in this case?



I believe interpolationg may work here, but I doubt the workspace or env would
be available since those are heavily agent-dependent. Basically this would be
referencing a variable before it has been created.

- 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

Bartłomiej Sacharski

unread,
May 17, 2017, 3:40:44 PM5/17/17
to Jenkins Users
 
Since this is an stage-only agent, would it be possible to define a new variable with that value on a pipeline level, or in previous stages, before there is a need to interpolate it for docker agent?
Reply all
Reply to author
Forward
0 new messages