azure-devops - 如何在 Azure DevOps 中使用 yaml 从管道运行 git 命令
问题描述
我只是想从 YAML 文件运行 Git 命令。这是我的 YAML 文件中的内容:
steps:
- checkout: self
persistCredentials: true
- task: Bash@3
inputs:
targetType: 'inline'
script: |
git config user.name "my_name"
git config user.password "my_password"
git clone https://my_repo@dev.azure.com/the_repo_stuff
git checkout dev
git checkout -b newer-branch
git commit -a -m 'new branch commit'
git push --set-upstream origin newer-branch
我越来越fatal: could not read Password for 'https://my_repo@dev.azure.com': terminal prompts disabled
我使用的密码是我在 Azure DevOps 中克隆窗口中生成的密码。
现在,我的目标只是让这个脚本创建一个分支。最终,我想传入变量并使其更复杂。
解决方案
我有点困惑为什么你需要这样的东西。
如果使用 pipeline.yaml 所在的相同存储库,您应该能够使用 git 命令,因为
- checkout: self
persistCredentials: true
如果您想签出不同的存储库,请考虑使用服务连接和多个存储库选项进行签出:
resources:
repositories:
- repository: MyGitHubRepo # The name used to reference this repository in the checkout step
type: github
endpoint: MyGitHubServiceConnection
name: MyGitHubOrgOrUser/MyGitHubRepo
- repository: MyBitbucketRepo
type: bitbucket
endpoint: MyBitbucketServiceConnection
name: MyBitbucketOrgOrUser/MyBitbucketRepo
- repository: MyAzureReposGitRepository # In a different organization
endpoint: MyAzureReposGitServiceConnection
type: git
name: OtherProject/MyAzureReposGitRepo
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- checkout: MyAzureReposGitRepository
- script: |
git checkout -b new-branch
git push --set-upstream origin newer-branch
- script: dir $(Build.SourcesDirectory)
来源:多个存储库文档
另请记住,多个存储库将更改默认存储库路径:
如果您使用默认路径,则添加第二个存储库签出步骤会更改第一个存储库的代码的默认路径。例如,当工具是唯一的存储库时,名为 tools 的存储库的代码将被签出到 C:\agent_work\1\s,但如果添加了第二个存储库,则工具将被签出到 C:\agent_work\ 1\s\工具。如果您有任何步骤依赖于原始位置的源代码,则必须更新这些步骤。
推荐阅读
- html - 悬停时翻译 css 时按钮文本模糊
- node.js - 智能合约:.methods.request().send() 不显示任何内容
- elasticsearch - Elasticsearch Kubernetes pod - 无法连接到端口 9300
- javascript - ReferenceError: $ is not defined - 它曾经工作正常,但现在它坏了 - Rails 5
- javascript - 如何防止在可放置 div 之外拖动(移动)元素?(仅限 Vanila JS)
- python - 如何在 Python 中每 2 秒调用一次函数?
- php - 仅从一个文件中删除 .php 扩展名以与 Laravel 路由器一起使用
- windows - 如何使用 dir 命令仅显示不带扩展名的文件名
- python - AttributeError: 'Turtle' 对象没有属性 'addshape'
- python - 在python中更改数组的某些索引的值