Reputation: 2629
I'm creating parameters in job A and want to use them in Job B, however Job B can not get the parameters value from Job A when I use template. Here is what I am trying:
fetchingfilenames.yml
jobs:
- job: A
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: myrepo
persistCredentials: true
- task: PowerShell@2
displayName: 'Fetching FileNames'
inputs:
targetType: 'inline'
script: |
Write-Host "Fetching filenames"
cd $(valuepath)
Write-Host $(valuepath)
##Listing files in the directory and saving them in an array
$a=ls
Write-Host "Files:"$a
$List = $a | foreach {'$(valuepath)/' + $_}
Write-Host "Files with complete path:"$List
$b = '"{0}"' -f ($List -join '","')
Write-Host $b ####Output is: "$(valuepath)/file1.yml, $(valuepath)/file2.yml"
Write-Host "##vso[task.setvariable variable=valuefiles;isOutput=true]$b"
name: fileoutput
deploy.yml
parameters:
files: []
jobs:
- job: B
dependsOn: A
pool:
vmImage: 'ubuntu-latest'
variables:
filenames: ${{ parameters.files }}
steps:
- checkout: myrepo
persistCredentials: true
- task: AzureCLI@2
inputs:
azureSubscription: 'mysubscription'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
echo "fetching filenames"
echo $(filenames) ####Error: output is empty
for i in $(echo $(filenames) | sed "s/,/ /g"); ###it doesn't run this line as it seems it can not find $(filename)
do
echo "valuefiles= $i";
done
azure-pipeline.yml
trigger:
branches:
include:
- master
paths:
include:
- azure-pipeline.yml
variables:
azureSubscription: 'mysubscription'
containerRegistry: 'myacr'
repository: 'myrepo'
chartPath: 'mypath'
resources:
repositories:
- repository: pipelinetemplates
type: github
name: myorg/mytemplates
endpoint: myendpoint
- repository: myrepo
type: github
name: myorg/myrepo
endpoint: myendpoint
trigger:
branches:
include:
- master
paths:
include:
- myfolder/*
stages:
- stage: Deploy
variables:
azureResourceGroup: 'myresourcegroup'
kubernetesCluster: 'myk8s'
domain: 'mydomain'
valuepath: myfolder
jobs:
- template: Template-Yaml/fetchingfilenames.yml@pipelinetemplates
- template: Template-Yaml/deploy.yml@pipelinetemplates
parameters:
##Fetching variable as parameters
files : $[dependencies.A.outputs['fileoutput.valuefiles']]
If I put Job A directly in azure-pipeline.yml and not use template for it, it workes perfectly fine however fetching Job A from template doesn't work as Job B can not fetch the parameter from Job A anymore.
Does anyone know what it is missing here?
Upvotes: 0
Views: 819
Reputation: 30313
fetchingfilenames.yml
jobs:
- job: A
steps:
- powershell: |
cd $(System.defaultworkingdirectory)
$a=ls
Write-Host "Files:"$a
$List = $a | foreach {'$(valuepath)/' + $_}
Write-Host "Files with complete path:"$List
$b = '"{0}"' -f ($List -join '","')
Write-Host $b
Write-Host "##vso[task.setvariable variable=valuefiles;isOutput=true]$b"
name: power
deploy.yml
parameters:
files: []
jobs:
- job: B
dependsOn: A
variables:
filenames: ${{parameters.files}}
steps:
- powershell: |
echo $(filenames)
foreach($a in $(filenames)){write-host $a}
azure-pipelines.yml:
resources:
repositories:
- repository: pipelinetemplates
type: git
name: PipelineBuildResourceYaml
stages:
- stage: SA
pool: Default
variables:
valuepath: "myfolder"
jobs:
- template: fetchingfilenames.yml@pipelinetemplates
- template: deploy.yml@pipelinetemplates
parameters:
##Fetching variable as parameters
files: $[dependencies.A.outputs['power.valuefiles']]
Output of Job B:
Upvotes: 2