I have a Jenkins pipeline that uses a Docker agent. I would like for the user to be able to specify which tag from the image repository is used for the pipeline. In the example below, the pipeline has an argument called tag
that the user can specify, which is appended to (concatenated) the image
argument to the docker agent. The full example is specified below.
#!/usr/bin/env groovy
def call(String tag = 'latest') {
pipeline {
agent {
docker {
image "analytics/rsc:${tag}"
registryUrl 'my.local.registry'
...
}
}
...
}
}
This throws the error
...12: Invalid config option "call" for agent type "docker". Valid config options are [image, alwaysPull, args, containerPerStageRoot, customWorkspace, label, registryCredentialsId, registryUrl, reuseNode] @ line 12, column 17.
image analytics/rsc:${tag}
I have tried other variations for the image
argument, including
image "analytics/rsc:" "${tag}"
and
image 'analytics/rsc:' tag
none of which have worked (I get errors similar to that of the first example, where the variable tag
is not evaluated and instead the literal text "tag"
is passed.
CodePudding user response:
This is a known problem that is reported as JENKINS-42369. Unfortunately, I don't think they will fix it any time soon, given that it was reported 6 years ago.
You can try this workaround, but workarounds do not work in all cases.