Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GoCD environment variables in task config #52

Closed
vdamle opened this issue Dec 1, 2017 · 5 comments
Closed

Use GoCD environment variables in task config #52

vdamle opened this issue Dec 1, 2017 · 5 comments

Comments

@vdamle
Copy link

vdamle commented Dec 1, 2017

Is it possible to use a environment variable such as GO_PIPELINE_NAME in the task configuration?

I tried snippet below and that fails to resolve the name.

              tasks:
                - fetch:
                    pipeline: "${GO_PIPELINE_NAME}"
                    stage: build

Basically, I'd like to not hard code the name of the pipeline (self) when fetching the build artifact so that I can alias the whole block and re-use it in other pipelines.

@vdamle
Copy link
Author

vdamle commented Dec 1, 2017

Also, documentation contains info on how to set parameters, but there is no info on how to reference a previously specified parameter. If you can provide an example, I can try it and I'm happy to create a PR with the doc update.

@tomzo
Copy link
Owner

tomzo commented Dec 1, 2017

Hi,

pipeline: "${GO_PIPELINE_NAME}"

Any kind of reference to environment variables similar to what you showed, will not work in yaml. GoCD never supported this in xml, therefore it will not work here. When you use ${GO_PIPELINE_NAME} in exec task, it is always used in bash -c '${GO_PIPELINE_NAME} ...' and actual extrapolation is done by bash, not agent.

documentation contains info on how to set parameters, but there is no info on how to reference a previously specified parameter.

The templates and parameters support is very limited because template must be in XML. So you cannot use anything like #{PARAM1} within yaml at this point.

In XML you need a template, e.g.

 <templates>
    <pipeline name="example">
      <stage name="defaultStage">
        <jobs>
          <job name="defaultJob">
            <tasks>
              <exec command="#{ARG}">
                <runif status="passed" />
              </exec>
            </tasks>
          </job>
        </jobs>
      </stage>
    </pipeline>
  </templates>

Then instead of referencing it from XML:

    <pipeline name="pipeline1" template="example">
      <params>
        <param name="ARG">value</param>
      </params>
      <materials>
        <git url="[email protected]:tomzo/gocd-yaml-config-plugin.git" />
      </materials>
    </pipeline>

You can use YAML:

pipe2:
  group: group1
  label_template: "foo-1.0-${COUNT}" 
  template: example
  parameters:
    arg: value
# no stages:

If you are only trying to avoid copy pasting blocks of yaml, you should see yaml aliases section.

I know there is a need for better templating, issue for this is #2

@tedder
Copy link
Contributor

tedder commented Dec 1, 2017

So you can set environment vars and params, but not use ones that would be there at runtime, like this:

        - exec:
            run_if: failed
            command: pipeline_failure.py
            arguments:
            - channel
            - '#{GO_SERVER_URL}' # link

Ah well.

@tomzo tomzo closed this as completed Dec 2, 2017
@vdamle
Copy link
Author

vdamle commented Dec 4, 2017

thanks for the feedback, understand the usage and limitations better

@jim-obrien-orig
Copy link

Just to update - this actually works now

  tasks:
    - exec:
        arguments:
          - -c
          - "mlflow experiments create --experiment-name $GO_PIPELINE_LABEL"
        command: bash
        run_if: passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants