I can't understand why dependencies don't work. I need to fix - task: cake@2 and other commented tasks. Now they looks like jobs, but I need to convert them into tasks. Here that task:
- task: Cake@2
displayName: Restore FE and Sitecore modules
condition: Or(eq(dependencies.check.outputs['ChangedFiles.BE'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Server :: Restore"
verbosity: "Quiet"
Version: "1.3.0"
Here's the whole code
name: test-build$(Rev:.r)
trigger:
branches:
include:
- develop
- release/*
paths:
exclude:
- "environment/**/*"
schedules:
- cron: 0 19 * * 1-5
displayName: evening-deployment
branches:
include:
- develop
always: false # whether to always run the pipeline or only if there have been source code changes since the last successful scheduled run. The default is false.
pool:
vmImage: "windows-latest"
variables:
- group: shared-variables
- name: ArtifactsLocation
value: "$(Build.Repository.LocalPath)/output"
- name: NUGET_PACKAGES
value: "$(Pipeline.Workspace)/.nuget/packages"
stages:
- stage: build
displayName: Build solution
jobs:
- job: Init
steps:
- ${{ if eq(variables['Build.Reason'],'PullRequest') }}:
- template: /environment/azure/templates/steps/validate-pr-title.yml
- task: gitversion/setup@0
displayName: Installing GitVersion tool
inputs:
versionSpec: "5.8.1"
- task: ChangedFiles@1
displayName: check
condition: eq(variables['Build.Reason'], 'PullRequest')
inputs:
rules: |
[FE]
**/*.json
**/*.ts
**/*.js
**/*.tsx
**/*.scss
**/*.html
**/*.css
[BE]
**/*.csproj
**/*.cs
**/*.yml
**/*.yaml
[SCContent]
**/*.json
**/*.yml
**/*.yaml
- task: GitVersion@5
displayName: Generate GitVersion
inputs:
versionSpec: "5.8.1"
runtime: "full"
configFilePath: "$(Build.Repository.LocalPath)/GitVersion.yml"
- script: |
echo deployInt: $(deployInt)
echo deployQa: $(deployQa)
displayName: Show variables for debug
condition: eq(variables['system.debug'], 'true')
- job: SitecoreCode
dependsOn: Init
steps:
- task: UseNode@1
displayName: Install correct Node.Js version
inputs:
version: "16.x"
- task: Cache@2
displayName: Cache cake packages
inputs:
key: 'cake | "$(Agent.OS)"'
restoreKeys: |
cake
path: "$(Build.Repository.LocalPath)/src/tools"
- task: Cache@2
displayName: Cache nuget modules
inputs:
key: 'nuget | "$(Agent.OS)" | **/packages.lock.json,!**/bin/**,!**/obj/**'
restoreKeys: |
nuget | "$(Agent.OS)"
nuget
path: "$(Build.Repository.LocalPath)/src/packages"
- task: Cache@2
displayName: Cache nuget package reference modules
inputs:
key: 'nuget_pr | "$(Agent.OS)" | $(Build.SourcesDirectory)/**/packages.lock.json'
path: "$(NUGET_PACKAGES)"
restoreKeys: |
nuget_pr | "$(Agent.OS)"
nuget_pr
- task: Cache@2
displayName: Cache node modules
inputs:
key: 'npm | "$(Agent.OS)" | $(Build.Repository.LocalPath)/src/package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
npm
path: "$(Build.Repository.LocalPath)/src/node_modules"
- task: Cache@2
displayName: Cache client node modules
inputs:
key: 'client_npm | "$(Agent.OS)" | $(Build.Repository.LocalPath)/src/rendering/package-lock.json'
restoreKeys: |
client_npm | "$(Agent.OS)"
client_npm
path: "$(Build.Repository.LocalPath)/src/rendering/node_modules"
- task: DownloadSecureFile@1
displayName: Download license
name: licenseFile
inputs:
secureFile: "license.xml"
- task: PowerShell@2
displayName: Place license file under /src folder
inputs:
targetType: "inline"
script: |
Move-Item $(licenseFile.secureFilePath) "$(Build.Repository.LocalPath)/src/" -Force
- template: /environment/azure/templates/steps/set-assembly-version.yml
- task: Cake@2
displayName: Restore FE and Sitecore modules
condition: Or(eq(dependencies.check.outputs['ChangedFiles.BE'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Server :: Restore"
verbosity: "Quiet"
Version: "1.3.0"
# - job: Restore_BE
# displayName: Restore BE
# dependsOn: Init
# condition: Or(eq(dependencies.check.outputs['CheckChanges.FE'], 'true'),ne(variables['Build.Reason'], 'PullRequest'))
# steps:
# - task: Cake@2
# displayName: Restore FE and Sitecore modules
# inputs:
# script: "$(Build.Repository.LocalPath)/src/build.cake"
# target: "Server :: Restore"
# verbosity: "Quiet"
# Version: "1.3.0"
# - job: Restore_FE
# displayName: Restore FE
# dependsOn: Init
# condition: Or(eq(dependencies.check.outputs['CheckChanges.FE'], 'true'),ne(variables['Build.Reason'], 'PullRequest'))
# steps:
# - task: Cake@2
# displayName: Restore FE and Sitecore modules
# inputs:
# script: "$(Build.Repository.LocalPath)/src/build.cake"
# target: "Client :: Restore"
# verbosity: "Quiet"
# Version: "1.3.0"
# drop empty config to make sure that JSS app picks settings from env vars
- powershell: |
$MyJsonHashTable = @{
'sitecore' = @{
'instancePath' = ''
'apiKey' = '$(JssApiKey)'
'deploySecret' = ''
'deployUrl' = ''
'layoutServiceHost' = ''
}
}
$MyJsonVariable = $MyJsonHashTable | ConvertTo-Json
Set-Content "$(Build.Repository.LocalPath)/src/rendering/scjssconfig.json" $MyJsonVariable
Write-Host ('{0}vso[task.logissue type={1}]{2}' -F '##', 'warning', "It would be nice to make app use SITECORE_API_KEY env var instead of API KEY in this file");
displayName: Generate scjssconfig.json with default API key
# TODO: Fix application to read SITECORE_API_KEY Variable
# - job: Build_BE
# displayName: Build BE
# dependsOn: Init
# condition: Or(eq(dependencies.check.outputs['CheckChanges.BE'], 'true'),ne(variables['Build.Reason'], 'PullRequest'))
# steps:
# - task: Cake@2
# displayName: Generate and Build FE and Sitecore
# inputs:
# script: "$(Build.Repository.LocalPath)/src/build.cake"
# target: "Server :: Build"
# verbosity: "Quiet"
# arguments: '--BuildConfiguration "Release" --ScSiteUrl "dummy"'
# Version: "1.3.0"
# - job: Build_FE
# displayName: Build FE
# dependsOn: Init
# condition: Or(eq(dependencies.check.outputs['CheckChanges.FE'], 'true'),ne(variables['Build.Reason'], 'PullRequest'))
# steps:
# - task: Cake@2
# displayName: Generate and Build FE and Sitecore
# inputs:
# script: "$(Build.Repository.LocalPath)/src/build.cake"
# target: "Client :: Build"
# verbosity: "Quiet"
# arguments: '--BuildConfiguration "Release" --ScSiteUrl "dummy"'
# Version: "1.3.0"
- ${{ if eq(variables['Build.Reason'],'PullRequest') }}:
- template: /environment/azure/templates/steps/npm-audit.yml
# - job: Unit_tests_BE
# displayName: Unit tests BE
# dependsOn: Init
# condition: Or(eq(dependencies.check.outputs['CheckChanges.BE'], 'true'),ne(variables['Build.Reason'], 'PullRequest'))
# steps:
# - task: Cake@2
# displayName: Run Unit tests
# inputs:
# script: "$(Build.Repository.LocalPath)/src/build.cake"
# target: "Server :: Tests"
# verbosity: "Quiet"
# Version: "1.3.0"
# - job: Unit_tests_FE
# displayName: Unit tests FE
# dependsOn: Init
# condition: Or(eq(dependencies.check.outputs['CheckChanges.FE'], 'true'),ne(variables['Build.Reason'], 'PullRequest'))
# steps:
# - task: Cake@2
# displayName: Run Unit tests
# inputs:
# script: "$(Build.Repository.LocalPath)/src/build.cake"
# target: "Client :: Tests"
# verbosity: "Quiet"
# Version: "1.3.0"
- task: PublishTestResults@2
displayName: Publish test results
inputs:
testResultsFormat: "XUnit"
testResultsFiles: "**/*.xml"
searchFolder: "$(ArtifactsLocation)/tests"
- task: PublishCodeCoverageResults@1
displayName: Publish code coverage
inputs:
codeCoverageTool: "Cobertura"
summaryFileLocation: "$(ArtifactsLocation)/tests/coverage/**/*.xml"
- ${{ if ne(variables['Build.Reason'],'PullRequest') }}:
- task: Cake@2
displayName: Publish Sitecore code
inputs:
script: "src/build.cake"
target: "004-Publish"
verbosity: "Quiet"
arguments: '--BuildConfiguration "Release" --PublishingTargetDir "$(ArtifactsLocation)/sitecore" --ClientConfigDir "$(Build.Repository.LocalPath)/src/rendering/sitecore/config"'
Version: "1.3.0"
- task: CopyFiles@2
displayName: Copy Sitecore root files
inputs:
SourceFolder: "$(Build.Repository.LocalPath)/src/configs/Sitecore"
TargetFolder: "$(ArtifactsLocation)/sitecore"
Contents: "**"
- task: CopyFiles@2
displayName: Copy transform files to separate artifact
inputs:
SourceFolder: $(ArtifactsLocation)/sitecore/ # string. Source Folder.
Contents: '**/*.transform' # string. Required. Contents. Default: '**'.
TargetFolder: $(ArtifactsLocation)/sitecore-transforms/ # string. Required. Target Folder.
- task: ArchiveFiles@2
displayName: "Archive config file transform artifacts"
inputs:
rootFolderOrFile: "$(ArtifactsLocation)/sitecore-transforms/"
archiveFile: "$(ArtifactsLocation)/sc/$(Build.BuildNumber)-transform.zip"
verbose: $(system.debug)
includeRootFolder: false
- task: DeleteFiles@1
displayName: Perform artifacts cleanup
inputs:
SourceFolder: "$(ArtifactsLocation)/sitecore"
RemoveDotFiles: true
Contents: |
**/obj/*
**/obj
**/*.wpp.targets
**/*.transform
# this hack is needed as our jss app have different roots now.
# hope in future it would be fixed
- powershell: |
$distFolder = $(Get-Item "$(ArtifactsLocation)/sitecore/dist/").FullName;
$files = Get-ChildItem "$distFolder" -Recurse -Force;
$TestFolder = New-Item $(Join-Path $distFolder "Test") -Type Directory -Force;
$optimaFolder = New-Item $(Join-Path $distFolder "optimahealth") -Type Directory -Force;
$files | % { Copy-Item $_.FullName -Destination $_.FullName.Replace($distFolder, "$($testFolder.FullName)/") -Force };
$files | % { Copy-Item $_.FullName -Destination $_.FullName.Replace($distFolder, "$($optimaFolder.FullName)/") -Force };
$files | % { if (Test-Path $_.FullName) { Remove-Item $_.FullName -Recurse -Force -Confirm:$false } }
displayName: Manually create folders for JSS app
- task: ArchiveFiles@2
displayName: "Archive Sitecore code artiffact"
inputs:
rootFolderOrFile: "$(ArtifactsLocation)/sitecore"
archiveFile: "$(ArtifactsLocation)/sc/$(Build.BuildNumber).zip"
verbose: $(system.debug)
includeRootFolder: false
- task: CopyFiles@2
displayName: Copy Id root files
inputs:
SourceFolder: "$(Build.Repository.LocalPath)/src/configs/Id"
TargetFolder: "$(ArtifactsLocation)/id"
Contents: "**"
- task: PublishPipelineArtifact@1
displayName: Publish Sitecore
inputs:
targetPath: "$(ArtifactsLocation)/sc"
artifactName: "SitecoreCode"
- task: PublishPipelineArtifact@1
displayName: Publish ID
inputs:
targetPath: "$(ArtifactsLocation)/id"
artifactName: "SitecoreID"
- job: SitecoreContent
dependsOn: Init
condition: eq(dependencies.check.outputs['ChangedFiles.SCContent'], 'true')
steps:
- template: /environment/azure/templates/steps/dotnet-cli.yml
parameters:
workingDir: "$(Build.Repository.LocalPath)/src"
- task: DotNetCoreCLI@2
displayName: Create Sitecore itempackage
inputs:
command: "custom"
custom: "sitecore"
arguments: "ser pkg create -o $(ArtifactsLocation)/w/test.itempackage"
workingDirectory: "$(Build.Repository.LocalPath)/src"
- ${{ if ne(variables['Build.Reason'],'PullRequest') }}:
- task: CopyFiles@2
displayName: Copy dotnet tools config
inputs:
SourceFolder: $(Build.Repository.LocalPath)/src/.config/ # string. Source Folder.
Contents: '**' # string. Required. Contents. Default: '**'.
TargetFolder: $(ArtifactsLocation)/w/.config/ # string. Required. Target Folder.
- task: CopyFiles@2
displayName: Copy sitecore dotnet config
inputs:
SourceFolder: $(Build.Repository.LocalPath)/src/ # string. Source Folder.
Contents: 'sitecore.json' # string. Required. Contents. Default: '**'.
TargetFolder: $(ArtifactsLocation)/w/ # string. Required. Target Folder.
- task: PublishPipelineArtifact@1
displayName: Publish Sitecore content
inputs:
targetPath: "$(ArtifactsLocation)/w/"
artifactName: "SitecoreContent"
## Deployment stage
- ${{ if ne(variables['Build.Reason'],'PullRequest') }}:
- template: /environment/azure/templates/deployment.yml
Reproduce the same issue with the similar YAML sample:
The cause of the issue is that we are not able to directly use dependencies expression in condition field.
To solve this issue, you need to change the following two points.
To use the variable in previous job, you can define variable to get the output variable in previous job. Then you can use the new variable to set the condition.
The format you used to get the the output variable is incorrect.
Based on your situation, here is the correct sample:dependencies.Init.outputs['ChangedFiles.FE']
.
Refer to the following example:
name: test-build$(Rev:.r)
trigger:
branches:
include:
- develop
- release/*
paths:
exclude:
- "environment/**/*"
schedules:
- cron: 0 19 * * 1-5
displayName: evening-deployment
branches:
include:
- develop
always: false # whether to always run the pipeline or only if there have been source code changes since the last successful scheduled run. The default is false.
pool:
vmImage: "windows-latest"
variables:
- group: shared-variables
- name: ArtifactsLocation
value: "$(Build.Repository.LocalPath)/output"
- name: NUGET_PACKAGES
value: "$(Pipeline.Workspace)/.nuget/packages"
stages:
- stage: build
displayName: Build solution
jobs:
- job: Init
steps:
- ${{ if eq(variables['Build.Reason'],'PullRequest') }}:
- template: /environment/azure/templates/steps/validate-pr-title.yml
- task: gitversion/setup@0
displayName: Installing GitVersion tool
inputs:
versionSpec: "5.8.1"
- task: ChangedFiles@1
displayName: check
condition: eq(variables['Build.Reason'], 'PullRequest')
inputs:
rules: |
[FE]
**/*.json
**/*.ts
**/*.js
**/*.tsx
**/*.scss
**/*.html
**/*.css
[BE]
**/*.csproj
**/*.cs
**/*.yml
**/*.yaml
[SCContent]
**/*.json
**/*.yml
**/*.yaml
- task: GitVersion@5
displayName: Generate GitVersion
inputs:
versionSpec: "5.8.1"
runtime: "full"
configFilePath: "$(Build.Repository.LocalPath)/GitVersion.yml"
- script: |
echo deployInt: $(deployInt)
echo deployQa: $(deployQa)
displayName: Show variables for debug
condition: eq(variables['system.debug'], 'true')
- job: SitecoreCode
dependsOn: Init
variables:
changes: $[dependencies.Init.outputs['ChangedFiles.FE'] ]
steps:
- task: UseNode@1
displayName: Install correct Node.Js version
inputs:
version: "16.x"
- task: Cache@2
displayName: Cache cake packages
inputs:
key: 'cake | "$(Agent.OS)"'
restoreKeys: |
cake
path: "$(Build.Repository.LocalPath)/src/tools"
- task: Cache@2
displayName: Cache nuget modules
inputs:
key: 'nuget | "$(Agent.OS)" | **/packages.lock.json,!**/bin/**,!**/obj/**'
restoreKeys: |
nuget | "$(Agent.OS)"
nuget
path: "$(Build.Repository.LocalPath)/src/packages"
- task: Cache@2
displayName: Cache nuget package reference modules
inputs:
key: 'nuget_pr | "$(Agent.OS)" | $(Build.SourcesDirectory)/**/packages.lock.json'
path: "$(NUGET_PACKAGES)"
restoreKeys: |
nuget_pr | "$(Agent.OS)"
nuget_pr
- task: Cache@2
displayName: Cache node modules
inputs:
key: 'npm | "$(Agent.OS)" | $(Build.Repository.LocalPath)/src/package-lock.json'
restoreKeys: |
npm | "$(Agent.OS)"
npm
path: "$(Build.Repository.LocalPath)/src/node_modules"
- task: Cache@2
displayName: Cache client node modules
inputs:
key: 'client_npm | "$(Agent.OS)" | $(Build.Repository.LocalPath)/src/rendering/package-lock.json'
restoreKeys: |
client_npm | "$(Agent.OS)"
client_npm
path: "$(Build.Repository.LocalPath)/src/rendering/node_modules"
- task: DownloadSecureFile@1
displayName: Download license
name: licenseFile
inputs:
secureFile: "license.xml"
- task: PowerShell@2
displayName: Place license file under /src folder
inputs:
targetType: "inline"
script: |
Move-Item $(licenseFile.secureFilePath) "$(Build.Repository.LocalPath)/src/" -Force
- template: /environment/azure/templates/steps/set-assembly-version.yml
- task: Cake@2
displayName: Restore FE and Sitecore modules
condition: Or(eq(variables['changes'], 'true'), ne(variables['Build.Reason'], 'PullRequest'))
inputs:
script: "$(Build.Repository.LocalPath)/src/build.cake"
target: "Server :: Restore"
verbosity: "Quiet"
Version: "1.3.0"
Refer to the doc about Use outputs in a different job