我正在使用 Azure DevOps Pipeline。根据我们的要求,我们需要在参数中传递代码库位置。并使用该参数并执行一些文件。而且我们还有多个代码库位置。
例如:
trigger:
- master
pool:
vmImage: ubuntu-latest
parameters:
- name: targetLocation
displayName: pathname ?
type: string
stages:
- stage: Bashscript
jobs:
- job:
continueOnError: false
steps:
- checkout: self
- task: TerraformInstaller@2
inputs:
terraformVersion: 'latest'
- script: |
**cd '$(Build.SourcesDirectory)/project-creation/'**
terraform init
chmod +x .terraform/providers/registry.terraform.io/microsoft/azuredevops/0.9.1/linux_amd64/terraform-provider-azuredevops_v0.9.1
terraform plan
- script: |
cd $(Build.SourcesDirectory)/$(path)
terraform init
chmod +x .terraform/providers/registry.terraform.io/microsoft/azuredevops/0.9.1/linux_amd64/terraform-provider-azuredevops_v0.9.1
terraform plan
- script: |
${{ parameters.targetDirectory }}
terraform init
chmod +x .terraform/providers/registry.terraform.io/microsoft/azuredevops/0.9.1/linux_amd64/terraform-provider-azuredevops_v0.9.1
terraform plan
我厌倦了这两项。
错误:
/home/vsts/work/_temp/sdsadasd-dsd-sds-b400-dfadfdasd.sh:第 1 行:workingDirectory:: 命令未找到 Terraform 在空目录中初始化!
您可以尝试如下设置 YAML。
trigger:
- master
trigger:
- master
pool:
vmImage: ubuntu-latest
parameters:
- name: targetLocations
displayName: 'pathname ?'
type: object
default:
- absolute/path/to/location_1
- absolute/path/to/location_2
. . .
- absolute/path/to/location_N
stages:
- stage: Bashscript
jobs:
- job:
continueOnError: false
steps:
- checkout: self
- task: TerraformInstaller@2
inputs:
terraformVersion: 'latest'
- ${{ each Location in parameters.targetLocations }}:
- script: |
terraform init
chmod +x .terraform/providers/registry.terraform.io/microsoft/azuredevops/0.9.1/linux_amd64/terraform-provider-azuredevops_v0.9.1
terraform plan
workingDirectory: ${{ Location }}