【发布时间】:2021-08-01 14:32:56
【问题描述】:
我想从位于步骤模板中的缓存步骤中的表达式创建缓存键。由于缓存是不可变的,我想每周或每月从一个干净的缓存开始。我的模板文件如下所示:
# steps-tpl.yml
steps:
- task: Cache@2
inputs:
key: compiler-cache | "<expression>" | "$(Agent.JobName)" | "$(Build.SourceBranch)" | "$(Build.SourceVersion)"
restoreKeys: |
compiler-cache | "<expression>" | "$(Agent.OS)" | "$(Agent.JobName)" | "$(Build.SourceBranch)" | "$(Build.SourceVersion)"
compiler-cache | "<expression>" | "$(Agent.OS)" | "$(Agent.JobName)" | "$(Build.SourceBranch)"
compiler-cache | "<expression>" | "$(Agent.OS)" | "$(Agent.JobName)" | "refs/heads/master"
path: $(Pipeline.Workspace)/ccache
displayName: 'ccache/clcache: Warm up cache'
表达式应该在一年中的每个星期给我一个不同的值,或者为简单起见,给我当前月份的数字。
我尝试了不同的表达方式,但都没有奏效。首先,我尝试将表达式放入无效的参数默认值中。然后我尝试将表达式直接放在这样的位置:
"${{ format('{0:MM}', pipeline.startTime) }}"
这也不起作用。也不是这个:
"$[format('{0:MM}', pipeline.startTime)]"
我猜运行时表达式在脚本上下文之外不可用。
我什至尝试在缓存前的一步中设置环境变量:
echo '##vso[task.setvariable variable=COMPILER_CACHE_KEY_PREFIX,isOutput=true]$[ counter(format("{0:yyyMMdd}", pipeline.startTime), 7) ]'
并将其与 $(previousStep.COMPILER_CACHE_KEY_PREFIX) 一起使用,这也不起作用。
如何将这样的表达式放入缓存键中?有可能吗?
【问题讨论】:
标签: azure azure-devops azure-pipelines azure-yaml-pipelines