更新Azure DevOps生成文件

编程入门 行业动态 更新时间:2024-10-08 22:13:00
本文介绍了更新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.

Note: I tested both on micrsoft-hosted agent and self-hosted agent. I only work out to run above git command on self-hosted agent. I always got NativeCommandError on Microsoft-hosted agent. Please create your self-hosted agent to run your yaml pipeline, if you get the same error.

_

Update:

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生成文件

本文发布于:2023-11-12 14:20:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581727.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   Azure   DevOps

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!