I don't believe there is any interpolation support for environment variables.
Normally I'd suggest that this type of logic is better to sit in a source controlled script than in ones pipeline configuration for ease of maintenance and to minimise coupling with the logic of your build tasks. However, for the specific example below, you might be able to use pipeline labels <https://docs.gocd.org/current/configuration/pipeline_labeling.html> and the GO_PIPELINE_LABEL env var to meet a similar need, if you are OK with the names of the entire pipeline (not just the stage) in GoCD itself changing from "$GO_PIPELINE_COUNTER" to "$GO_REVISION-$GO_PIPELINE_COUNTER" In this case you should be able to set the label_template to "${git}-${COUNT}" (or a variation with a truncated revision) and then use $ GO_PIPELINE_LABEL <https://docs.gocd.org/current/faq/dev_use_current_revision_in_build.html#standard-gocd-environment-variables> for your image tag. See https://docs.gocd.org/current/configuration/pipeline_labeling.html and Groovy DSL docs at https://github.com/gocd-contrib/gocd-groovy-dsl-config-plugin/blob/4b19c96dc805ee7bbe292a9bc8adb65a05ba0612/dsl/src/main/java/cd/go/contrib/plugins/configrepo/groovy/dsl/Pipeline.java#L67-L98 . -Chad On Thu, Dec 22, 2022 at 11:22 AM 'Alexey Savchkov' via go-cd < [email protected]> wrote: > Is it possible to create an environment variable referring to another > existing environment variable in a pipeline definition? I use the Groovy > configuration plugin and would like to do something like this: > stage('Build') { > environmentVariables = [ > IMAGE_TAG: "$GO_REVISION-$GO_PIPELINE_COUNTER" > ] > ... > The variables must be resolved at runtime, not ath the time of creating > the configuration. Is this possible at all? In all my attempts I only get > errors like > "No such property: GO_REVISION for class: > cd.go.contrib.plugins.configrepo.groovy.dsl.Stage" > The only workaround I see is to set environment variables directly in the > bash string before executing the actual bash commands but then this has to > be done for every bash task and I don't quite like it. > > -- > You received this message because you are subscribed to the Google Groups > "go-cd" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/go-cd/d25de2ad-935e-4f93-a88c-a929c94fe468n%40googlegroups.com > <https://groups.google.com/d/msgid/go-cd/d25de2ad-935e-4f93-a88c-a929c94fe468n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "go-cd" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/go-cd/CAA1RwH8Fs2hFHvTqQ9uPZFb%2BAP6GWfV_SN3Xk%3Db1kcuSk8R6Rw%40mail.gmail.com.
