skip to Main Content
  - stage: publish_service_names
    dependsOn: build_code
    jobs:
      - job: get_services
        pool:
          ${{ if eq(parameters.useCustomAgentPool, true) }}:
            name: ${{ parameters.customAgentPoolName }}
          ${{ if eq(parameters.useCustomAgentPool, false) }}:
            vmImage: ubuntu-latest
        steps:
          - bash: |
              services=$(cat $(Pipeline.Workspace)/variables/services.txt)
              echo "service List : $services"
              echo "##vso[task.setvariable variable=serviceName;]$services"
            name: getservices
  - ${{ if and(eq(parameters.buildDockerImages, true), eq(parameters.buildSingleServiceDockerImages, true)) }}:
      - stage: publish_docker_images
        dependsOn: publish_service_names
        variables:
          services: $[stageDependencies.publish_service_names.get_services.outputs['getservices.serviceName']]
        jobs:
**          - ${{ each service in split(variables.services, ',') }}:
**            - template: ./build-push-single-docker.yaml
              parameters:
                acrServiceConnection: ${{ parameters.acrServiceConnection}}
                serviceName: "${{ service }}"
                friendlyName: "${{ service }}"
                repositoryPathPrefix: ${{ parameters.repositoryPathPrefix }}

build-push-single-docker.yaml

jobs:
  - job: publish_${{ parameters.friendlyName }}
    pool:
      ${{ if eq(parameters.useCustomAgentPool, true) }}:
        name: ${{ parameters.customAgentPoolName }}
      ${{ if eq(parameters.useCustomAgentPool, false) }}:
        vmImage: ubuntu-latest
    steps:
      - bash: |
          echo "##vso[task.setvariable variable=buildArtifact;]ailens_services_supplemented_with_client_package"
        condition: eq('${{ parameters.addClientToSingleboxAndGUI }}', true)
        displayName: "Set artifact name"

Tried direct use of

  1. the stageDependencies variable directly in the template loop expression
  2. assigning it to variable and using the variable

both of them didnt solve my purpose.

2

Answers


  1. Chosen as BEST ANSWER
    jobs:
          - ${{ each service in split(variables.services, ',') }}:
            - template: ./build-push-single-docker.yaml
              parameters:
                acrServiceConnection: ${{ parameters.acrServiceConnection}}
                serviceName: "${{ service }}"
                friendlyName: "${{ service }}"
                repositoryPathPrefix: ${{ parameters.repositoryPathPrefix }}
    

    The job execution is not looping over all service names.

    • publish S1
    • publish S2

  2. It looks like you are missing isOutput=true property.
    Try

    echo "##vso[task.setvariable variable=serviceName;isOutput=true]$services"
    

    More info here: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=bash#set-an-output-variable-for-use-in-future-stages

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search