具有可变深度和默认值的 Azure 管道 git 结帐
Azure pipeline git checkout with variable depth and default value
我在 Azure Pipeline YML 中有以下代码。
在 checkout.yml 中(用作模板)
- checkout: self
clean: true
fetchDepth: 100
lfs: true
submodules: recursive
persistCredentials: true
我想让 fetchDepth 动态化。我可以使用一个变量。但我也想为该变量设置一个默认值。目的是调用者可以将此文件作为模板包含在内。
some_file.yml:
steps:
template: checkout.yml
我想让 some_file.yml 可以 将 fetchDepth 设置为其他值,但不需要这样做。我尝试使用 $(something) 但如何设置默认值?还是 $[something] 的使用方式?
我被困在这里,但我想答案可能很简单:-(
谢谢,
您可以通过模板参数并在参数本身内使用 fetchDepth 的默认值来完成此操作。
这是一个使用您的结帐任务的示例:
结帐任务模板-example.yml
parameters:
fetchDepth: 100
steps:
- checkout: self
clean: true
fetchDepth: ${{ parameters.fetchDepth }}
lfs: true
submodules: recursive
persistCredentials: true
结帐管道-example.yml
name: Whosebug-Example-Checkout
trigger:
- none
stages:
- stage: Deploy_Production
pool:
vmImage: ubuntu-latest
jobs:
- deployment: DeployWeb
displayName: Deploy Web App
environment: YourApp-QA
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
# Example: Use Default
- template: checkout-task-template-example.yml
# Example: Override Default
- template: checkout-task-template-example.yml
parameters:
fetchDepth: 10
这是 Microsoft 关于 YAML 模板和具体参数的文档:
我在 Azure Pipeline YML 中有以下代码。
在 checkout.yml 中(用作模板)
- checkout: self
clean: true
fetchDepth: 100
lfs: true
submodules: recursive
persistCredentials: true
我想让 fetchDepth 动态化。我可以使用一个变量。但我也想为该变量设置一个默认值。目的是调用者可以将此文件作为模板包含在内。
some_file.yml:
steps:
template: checkout.yml
我想让 some_file.yml 可以 将 fetchDepth 设置为其他值,但不需要这样做。我尝试使用 $(something) 但如何设置默认值?还是 $[something] 的使用方式?
我被困在这里,但我想答案可能很简单:-(
谢谢,
您可以通过模板参数并在参数本身内使用 fetchDepth 的默认值来完成此操作。
这是一个使用您的结帐任务的示例:
结帐任务模板-example.yml
parameters:
fetchDepth: 100
steps:
- checkout: self
clean: true
fetchDepth: ${{ parameters.fetchDepth }}
lfs: true
submodules: recursive
persistCredentials: true
结帐管道-example.yml
name: Whosebug-Example-Checkout
trigger:
- none
stages:
- stage: Deploy_Production
pool:
vmImage: ubuntu-latest
jobs:
- deployment: DeployWeb
displayName: Deploy Web App
environment: YourApp-QA
pool:
vmImage: 'ubuntu-latest'
strategy:
runOnce:
deploy:
steps:
# Example: Use Default
- template: checkout-task-template-example.yml
# Example: Override Default
- template: checkout-task-template-example.yml
parameters:
fetchDepth: 10
这是 Microsoft 关于 YAML 模板和具体参数的文档: