azure - 在模板中使用 powershell 脚本

标签 azure powershell yaml azure-pipelines azure-rm-template

我有一个 powershell 脚本,我想在模板中使用它(编辑文件)。我想将脚本存储在包含 yaml 模板的存储库中。然后我想从另一个存储库调用该模板。一切似乎都工作正常,但触发构建时似乎没有拉入 powershell 脚本。我知道我可能需要做一些额外的设置。

此脚本更改 vdproj 文件。我希望它保留在包含模板的存储库中,因为我希望能够从调用该模板的其他存储库中重用该脚本。

我收到的错误: enter image description here

yaml 模板:

parameters:
  ArtifactPath: ''
  ArtifactName: ''
  ArtifactPublish: false
  Artifacts: []
  PublishClient: false
  Solution: '**/*.sln'
  
jobs:
- job: Build
  displayName: 'Build, Pack, and Publish'
  pool:
    name: 'Windows Self Hosted'
  variables:
    solution: ${{ parameters.Solution }}
    buildPlatform: 'Any CPU'
    buildConfiguration: 'Release'

  steps:
  - task: NuGetToolInstaller@1
    displayName: "Install Nuget Tool"

  - task: NuGetCommand@2
    displayName: 'Restore Nuget Packages'
    inputs:
      command: 'restore'
      restoreSolution: '$(solution)'
      feedsToUse: 'select'
      vstsFeed: '507de2ce-fb6f-41a2-a787-fbfb891bec38'

   - task: PowerShell@2
    inputs:
      targetType: 'filePath'
      filePath: $(System.DefaultWorkingDirectory)\RW.Scripts\PowerShell\Client\UpdateProductVersion.ps1
      arguments: > # Use this to avoid newline characters in multiline string
        -ver $(Build.BuildId)
        -filename "$(System.DefaultWorkingDirectory)\Installers\InstallerExample\InstallerExample.vdproj"
    displayName: 'Change Project Version'

  - script: |
      cd C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE
      devenv "$(Build.Repository.LocalPath)\Example.sln"  /Project "$(Build.Repository.LocalPath)\Installers\InstallerExample\InstallerExample.vdproj" /Build "$(buildConfiguration)"
    displayName: 'Build MSI with DevEnv.'
    condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/development'))

  - task: VSTest@2
    displayName: 'Run Unit Tests'
    inputs:
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'

  - task: PublishSymbols@2
    displayName: 'Publish Symbols to Symbol Server'
    inputs:
      SearchPattern: '**/bin/**/*.pdb'
      SymbolServerType: 'TeamServices'
            
    - ${{ each artifact in parameters.Artifacts }}:
      - ${{ if eq(artifact.PublishClient, true) }}:
        - task: PublishPipelineArtifact@1
          displayName: 'Publish Artifact: ${{ artifact.ArtifactName }}'
          inputs:
            targetPath: '$(Build.SourcesDirectory)/${{ artifact.ArtifactPath }}'
            artifactName: '${{ artifact.ArtifactName }}'

调用模板的yaml:

trigger:
  - release
  - development
  - master
  - feature/*
  - task/*

resources:
  repositories:
    - repository: templates
      name: Project/RepoWithTemplate
      type: git
      ref: refs/heads/development

# This sets the BuildNumber variable
name: $(Date:yyyyMMdd).$(Rev:r)-$(SourceBranchName)
  
jobs:
- template: RW.Yaml.Templates/example.yml@templates
  parameters:
    Solution: '**/Example.sln'
    ArtifactPublish: true
    Artifacts:
    - ArtifactPath: 'Installers/ExampleInstaller/$(buildConfiguration)'
      ArtifactName: 'example'
      ${{ if eq(variables['Build.SourceBranchName'], 'development') }}:
        PublishClient: true

最佳答案

我弄清楚了这一点,现在感觉很愚蠢。我只需要像下面这样检查两个存储库就可以了。

  - checkout: self
  - checkout: templates

关于azure - 在模板中使用 powershell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65185510/

相关文章:

azure - Azure 中的 npm 使用哪个 .ssh/known_hosts 文件?

azure - HDInsight字数映射减少卡住映射器的程序的程序100%和缩减器0%

activerecord - 导轨 4 : Export database to YAML

yaml - 更改 circle.yml 文件位置

powershell - 如何将 ASCII Art 输出到控制台?

yaml - 如何在 Helm chart 中从 values.yaml 获取值到 _helpers.tpl

python - 错误无效输入数据类型 : Input of type 'Unknown' is not supported in azure (azureml. train.automl)

asp.net-mvc - Azure Web 作业 - 数据处理

powershell - 如何在企业中使用 PowerShell 和 PowerShell 模块

powershell:将文件内容通过管道传输到命令中