英文:
exporting & re-using variables from Stage1 to Stage2 in Azure devops
问题
- 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
- bash: |
- job: get_services
- ${{ 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 }}
- template: ./build-push-single-docker.yaml
- ${{ each service in split(variables.services, ',') }}:
- stage: publish_docker_images
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"
- bash: |
英文:
- 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
- the stageDependencies variable directly in the template loop expression
- assigning it to variable and using the variable
both of them didnt solve my purpose.
答案1
得分: 1
看起来你缺少了 isOutput=true
属性。
尝试
echo "##vso[task.setvariable variable=serviceName;isOutput=true]$services"
更多信息请查看这里: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
英文:
It looks like you are missing isOutput=true
property.
Try
echo "##vso[task.setvariable variable=serviceName;isOutput=true]$services"
答案2
得分: 0
jobs:
- ${{ each service in split(variables.services, ',') }}:
- template: ./build-push-single-docker.yaml
parameters:
acrServiceConnection: ${{ parameters.acrServiceConnection}}
serviceName: "${{ service }}"
friendlyName: "${{ service }}"
repositoryPathPrefix: ${{ parameters.repositoryPathPrefix }}
- template: ./build-push-single-docker.yaml
The job execution is not looping over all service names.
- publish S1
- publish S2
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论