bash - Bash 脚本在本地成功执行,但不在 Azure Devops 管道中
问题描述
我有一个在本地环境中成功执行的 bash 脚本:
#!/bin/bash
#build changelog
version="Version: "
current_date=`date`
cat <(printf " \n") <(echo $version $env:BUILD_BUILDNUMBER $current_date) <(tail -n+6 pr-changelog.md) ./CHANGELOG.md > output
mv output ./CHANGELOG.md
但是,在我的 Azure Devops 管道中使用 Bash 构建包时,虽然脚本成功,但不会引发任何错误并且管道完成,脚本中的更改不会发生。
该脚本将行从一个文件复制到CHANGELOG.md
以及其他一些小东西。在本地复制文本,但运行管道后,CHANGELOG.md
我的分支中的文件没有更改。
我可以期望这行得通吗?如果不行,我应该采取哪些进一步的步骤?
TIA
解决方案
Bash 脚本在本地成功执行,但不在 Azure Devops 管道中
当我们在 Azure 管道上执行构建时,它会将源从 repo 签出到构建代理,并且下一个操作也在代理上完成。它不会直接影响repo,这样可以保护我们repo中源的安全。
这就是为什么脚本中的更改不会发生在您的分支中的原因。
为了解决这个问题,我们需要通过 git 命令将这个更改提交到 repo:git add
git commit
和git push
:
git config --global user.email "xxx@xyz.com"
git config --global user.name "Admin"
cd "$(System.DefaultWorkingDirectory)"
version="Version: "
current_date=`date`
cat <(printf " \n") <(echo $version $env:BUILD_BUILDNUMBER $current_date) <(tail -n+6 pr-changelog.md) ./CHANGELOG.md > output
mv output ./CHANGELOG.md
git add CHANGELOG.md
git commit -m "copies lines to CHANGELOG.md"
git push https://<PAT>@dev.azure.com/YourOrganization/YourProject/_git/YourProject HEAD:master
我用 Azure 管道对其进行了测试,效果很好。
推荐阅读
- python - 如何使用 PIL 优化调色板图像大小?
- python - pandas 根据前缀重塑 long
- objective-c - 通过Objective C中的lat long列表确定提供的lat long是否在区域中
- swift - 如何使用 UIView 单元格中的 firebase 用户名重命名不同视图控制器中的按钮?
- winforms - 创建基于.net core 3的WinForm项目
- .net - 直接访问 S3 Glacier Deep Archive
- bash - AOSP 构建日志中的这个 clang 命令中的 @ 是什么意思?
- selenium - 如何查找在页面上出现多次的类元素的 XPath?
- java - 如何使用 java 在 selenium 中执行静态等待?
- java - 解析具有可能作为字符串或字符串数组的属性的 json