Skip to content

Commit 833efe8

Browse files
authored
Create SHA256 of Project List for Cache Key (Azure#30714)
Create SHA256 of Project List for Cache Key
1 parent 8c18436 commit 833efe8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

eng/pipelines/templates/steps/generate-project-list-and-cache-maven-repository.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ parameters:
2020
default: test
2121

2222
steps:
23+
# Create the ProjectList and ProjectListSha256 variables.
24+
# The ProjectList is used by subsequent steps and tasks to run CI.
25+
# The ProjectListSha256 is used by the cache key, previously the cache key was using ProjectList but it was found
26+
# that long cache keys cause caching to fail.
2327
- pwsh: |
2428
$artifacts = '${{ convertToJson(parameters.Artifacts) }}' | ConvertFrom-Json
2529
$additionalModules = '${{ convertToJson(parameters.AdditionalModules) }}' | ConvertFrom-Json
@@ -35,12 +39,18 @@ steps:
3539
3640
Write-Host "ProjectList = $projects"
3741
Write-Host "##vso[task.setvariable variable=ProjectList;]$projects"
42+
43+
$sha256 = new-object -TypeName System.Security.Cryptography.SHA256Managed
44+
$utf8 = new-object -TypeName System.Text.UTF8Encoding
45+
46+
$projectListSha256 = [Convert]::ToBase64String($sha256.ComputeHash($utf8.GetBytes($projects)))
47+
Write-Host "##vso[task.setvariable variable=ProjectListSha256;]$projectListSha256"
3848
displayName: Initialize project list variable
3949

4050
- task: Cache@2
4151
inputs:
4252
# Note: CacheSalt is only intented to be used in special cases, as a build is queued, to force a cache miss.
4353
# This would be set as a variable in the UI when the run is queued.
44-
key: 'maven | "$(CacheSalt)" | "$(Agent.OS)" | $(Build.SourcesDirectory)/eng/versioning/external_dependencies.txt | "$(ProjectList)" | "${{ parameters.JobType }}" | "$(TestFromSource)"'
54+
key: 'maven | "$(CacheSalt)" | "$(Agent.OS)" | $(Build.SourcesDirectory)/eng/versioning/external_dependencies.txt | "$(ProjectListSha256)" | "${{ parameters.JobType }}" | "$(TestFromSource)"'
4555
path: $(MAVEN_CACHE_FOLDER)
4656
displayName: Cache Maven local repo

0 commit comments

Comments
 (0)