本文介绍了更新Azure DevOps生成文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新powershell文件的模块版本,我使用了Yaml/Powershell命令,并且能够更改模块版本号,但是现在我想将所做的更改保存到名为fileLocation的文件位置变量中,我不知道如何保存对此.psd1文件所做的更改.当前的Yaml脚本是:

 触发:分支机构:包括:- 掌握变量:版本号:'1.0.$(Build.BuildNumber)'installModule:Install-Module-名称PowerShellGet -Scope CurrentUser-存储库PSGallery -Force -Verbose数据:获取内容-Path James.Artifactory.psd1fileLocation:James.Artifactory.psd1版本更新:Update-ModuleManifest -Path James.Artifactory.psd1 -ModuleVersion"$(versionNumber)"脚步:#运行一次后删除或注释掉installModule#-pwsh:$(installModule)-pwsh:$(versionUpdate)-pwsh:$(数据)-pwsh:获取内容-Path $(fileLocation)-pwsh:外文件-FilePath $(fileLocation) 
解决方案

您可以在powershell脚本中运行git命令以将更改提交到存储库中.

首先,您需要转到项目设置下的存储库.单击 Git存储库,在安全性页中,单击加号(+)并搜索组 {您的项目名称}构建服务({您的组织名称}),然后单击添加它,然后在访问控制摘要页面中,授予贡献和读取权限.请检查下面的屏幕截图.

然后将您的yaml文件配置为清除源代码并

然后选中覆盖yaml ... 禁用持续集成

I would like to update the module version of powershell file, I used Yaml/Powershell commands and was able to change the module version number but now I want to save my changes to the file location variable called fileLocation I don't know how I could save the changes I made to this .psd1 file. Current Yaml script is:

trigger:
  branches:
    include:
      - master

variables:
  versionNumber: '1.0.$(Build.BuildNumber)'
  installModule: Install-Module -Name PowerShellGet -Scope CurrentUser -Repository PSGallery -Force -Verbose
  data: Get-Content -Path James.Artifactory.psd1
  fileLocation: James.Artifactory.psd1
  versionUpdate: Update-ModuleManifest -Path James.Artifactory.psd1 -ModuleVersion "$(versionNumber)"

steps:
  #Remove or commentout installModule after running it once
  #- pwsh: $(installModule)
  - pwsh: $(versionUpdate)
  - pwsh: $(data)
  - pwsh: Get-Content -Path $(fileLocation)
  - pwsh: Out-File -FilePath $(fileLocation)
解决方案

You can run git command in powershell script to commit the changes to your repository.

First you need to go the Repositories under project settings. Click Git Repositories, in the security page, click plus(+) and search for group {your project name} build service({your org name}) and click to add it, and In the access control summary page, grant contribute and read permission. Please check below screenshot.

Then configure your yaml file to clean source and allow script accessthe system token by using checkout. Below script is just an example.

pool: default

steps:

- checkout: self
  clean: true
  persistCredentials: true

   - powershell: |
    cd $(System.defaultworkingdirectory)
    git checkout -B master

    New-Item -Path '$(System.defaultworkingdirectory)\newfile366.txt' -ItemType File

    git add .
    git commit -m "Update"
    git push origin master

Above script run git checkout -B master to checkout master branch. And I create a new file with New-Item command. Then I commit the changes and push to my azure repos.

_

Above git commands will commit changes to your master branch, and it will trigger another build if you enable CI build. You can disable CI build from the Triggers

Click the 3 dots and choose Triggers.

Then check override the yaml ... and Disable continuous integration

这篇关于更新Azure DevOps生成文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:15