Concourse pipeline variables on resources

21 Views Asked by At

Q1

I would like declare variable with default values and use it in the concourse resources

e.g. in the start of the pipeline.yml, the below variable is declared.

PROJECT: hello-world

and then use it in resources/resource_types like

groups:
  - name: ((PROJECT))
    jobs:
      - pull-request
      - create-artifacts

Now getting error like

  - groups.((PROJECT)): '((PROJECT))' is not a valid identifier: must start with a lowercase letter

Actually the variable is only resolved when --var PROJECT=hello-world is passed when setting the pipeline.

Curious; why it is not referring the variable declared inside the pipeline.yml I do not want to pass any additional argument when setting the pipeline, would like to declare it in the yml itself.

Q2:

The above question Q1 was resolved with anchors and aliases. Please refer my answer.

But the same is not working with resources

REPOSITORY_NAME: &REPOSITORY_NAME hello-world-repo

resources:
  - name: pull-request-branch
    check_every: 1m
    type: pull-request
    icon: source-pull
    source:
      repo: cahcommercial/*REPOSITORY_NAME

Any help please.

1

There are 1 best solutions below

0
Kanagavelu Sugumar On

Q1:

PROJECT: &PROJECT hello-world


groups:
  - name: *PROJECT
    jobs:
      - pull-request
      - create-artifacts

Q2

REPOSITORY_NAME: &REPOSITORY_NAME
  repo: owner/hello-world-repo

resources:
  - name: pull-request-branch
    check_every: 1m
    type: pull-request
    icon: source-pull
    source:
      <<: *REPOSITORY_NAME

Finally I am feeling that passing the variables from command line is the best option. It allows me to reuse the pipeline.yml

https://concourse-ci.org/vars.html#static-vars

fly -t target set-pipeline --pipeline pipeline-name \
  -c pipeline.yml \
  -v PROJECT=hello-world \

and then use the variable syntax in the pipeline.yml

groups:
  - name: ((PROJECT))
    jobs:
      - pull-request
      - create-artifacts