Interpolating variables in agent's docker parameter

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Interpolating variables in agent's docker parameter

Bartłomiej Sacharski
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?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fd047f0f-2aba-4700-a7b8-caa20658e681%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Interpolating variables in agent's docker parameter

R. Tyler Croy
(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: [hidden email]

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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/20170517192334.z67kdyaotzh2ogod%40blackberry.coupleofllamas.com.
For more options, visit https://groups.google.com/d/optout.

signature.asc (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Interpolating variables in agent's docker parameter

Bartłomiej Sacharski
(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: <<a href="https://github.com/rtyler" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frtyler\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtsnCUZ085B8982iTQ2KFqz5gYhw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Frtyler\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFtsnCUZ085B8982iTQ2KFqz5gYhw&#39;;return true;">https://github.com/rtyler>
  Chatter: <<a href="https://twitter.com/agentdero" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftwitter.com%2Fagentdero\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEILlTAfpmlCsYIT_Phy_UKs4kUlw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Ftwitter.com%2Fagentdero\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEILlTAfpmlCsYIT_Phy_UKs4kUlw&#39;;return true;">https://twitter.com/agentdero>
     xmpp: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="dU4VY02cAQAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rty...@...

  % gpg --keyserver <a href="http://keys.gnupg.net" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fkeys.gnupg.net\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGGvem0n8cSWWfyOfhzR-uVSpk4NQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fkeys.gnupg.net\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGGvem0n8cSWWfyOfhzR-uVSpk4NQ&#39;;return true;">keys.gnupg.net --recv-key 1426C7DC3F51E16F
------------------------------------------------------
 
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?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/09f0f376-021c-4567-912e-68b15f84cd78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.