小编Cla*_*ier的帖子

Azure管道:如何在条件中使用输出变量

我正在开发在 Windows 自托管代理上运行的管道。我需要调用一个在一个阶段初始化变量的脚本,并在下一阶段的条件下使用该变量。

这是我的 Yaml:

stages:
  - stage: Init
    jobs:
    - job: RunScript
      steps:
        - task: PowerShell@2
          name: compareFiles
          inputs:
            targetType: filePath
            filePath: '***\compareFileContent.ps1'

  - stage: DisplayStage
    dependsOn: Init
    variables:
      areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
    jobs:
    - job: Display
      steps:
        - script: |
            echo $(areFilesDifferent)

  - stage: DeploymentStage
    dependsOn: DisplayStage
    variables:
      areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
    condition: eq( '$(areFilesDifferent)', 'true' )
    jobs:
    - deployment: DeploymentJob
      environment: 'ATest'
      strategy:
        runOnce:
          deploy:
            steps:
              - checkout: none
              - task: CmdLine@2
                inputs:
                  script: |
                    echo EnvName …
Run Code Online (Sandbox Code Playgroud)

powershell azure-pipelines azure-pipelines-yaml

4
推荐指数
1
解决办法
3235
查看次数

在Azure管道中,Powershell如何使任务失败?

我正在 Windows 自托管代理上的 Azure Pipelines 上工作。我需要我的管道来运行 PowerShell 脚本,如果脚本成功,则下一阶段进行部署,否则任务失败,我们必须修复某些内容并恢复任务

我将描述管道从一开始就做什么,因为它可能有助于理解。

首先,管道调用带参数的模板:

stages:
  - template: release.yml@templates
    parameters:
      dbConnectionString: ''
Run Code Online (Sandbox Code Playgroud)

模板release.yml@templates如下:

parameters:
- name: 'dbConnectionString'
  default: ''
  type: string
Run Code Online (Sandbox Code Playgroud)

第一阶段只是简单地构建项目,工作正常

stages:
  - stage: Build
      - job: Build_Project
        steps:
          - checkout: none
          - template: build.yml          
Run Code Online (Sandbox Code Playgroud)

第二阶段取决于前一阶段的结果。对于模板的某些情况,没有要检查的数据库,因此我仅提供一个参数来运行作业。然后,我只想在 DBCheck 成功或没有参数的情况下运行 CompareFile 脚本。

  - stage: Deploy
    dependsOn: 
    - Build
    condition: eq( dependencies.Build.result, 'Succeeded' )
    jobs:
    - job: CheckDb
      condition: ne('${{ parameters.dbConnectionString }}', '')
      steps:
        - checkout: none
        - template: validate-db.yml@templates
          parameters:
            ConnectionString: '${{ parameters.dbConnectionString }}'

    - job: …
Run Code Online (Sandbox Code Playgroud)

azure-powershell azure-pipelines-yaml

4
推荐指数
1
解决办法
7732
查看次数