在模板中使用 powershell 脚本

Using a powershell script in a template

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

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

我遇到的错误:

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 Studio19\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