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

extending a pipeline to multiple templates with parameterised condition #4

Open
Sheelayathakula opened this issue Jul 18, 2024 · 1 comment

Comments

@Sheelayathakula
Copy link

Hello,

I have a question regarding extending a template. I want to create a jar or containerised image based on the parameterised condition.

for example:

if ${{ parameters.x }}', 'True
extends:
template: x/create-library.yml
{{ else }}:
extends:
template: x/create-image.yml

I havent tested this yet.

@joshjohanning
Copy link
Owner

joshjohanning commented Jul 22, 2024

@Sheelayathakula I tested this out quick, and according to the pipeline editor/validator, this doesn't work 😢

This example sees duplicate entry errors for the 2 extends: properties:

${{ if eq(variables.foo, 'adaptum') }}:
  extends:
    template: template/extends.yml
    parameters:
      usersteps:
      - script: echo "This is my first step"
      - script: echo "This is my second step"
${{ if eq(variables.foo, 'other') }}:
  extends:
    template: template/extends.yml
    parameters:
      usersteps:
      - script: echo "This is my first step"
      - script: echo "This is my second step"

I see duplicate entry errors for template and parameters for this example too:

extends:
  ${{ if eq(variables.foo, 'adaptum') }}:
    template: template/extends.yml
    parameters:
      usersteps:
      - script: echo "This is my first step"
      - script: echo "This is my second step"
  ${{ if eq(variables.foo, 'other') }}:
    template: template/extends.yml
    parameters:
      usersteps:
      - script: echo "This is my first step"
      - script: echo "This is my second step"

You would probably have to key on the parameter itself for the extends template path, something like:

extends:
  template: template/${{ parameters.x }}.yml
  parameters:
    usersteps:
    - script: echo "This is my first step"
    - script: echo "This is my second step"

As a reference, I have more information on the extends template in blog post from a few years ago here: https://josh-ops.com/posts/extends-template/ (I don't discuss conditionals, though)

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

2 participants