gpt4 book ai didi

azure-devops - 如何在 Azure DevOps 中使用 yaml 从管道运行 git 命令

转载 作者:行者123 更新时间:2023-12-04 08:04:50 25 4
gpt4 key购买 nike

我只想从 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

我遇到了致命问题:无法读取“https://my_repo@dev.azure.com”的密码:终端提示已禁用

我使用的密码是我在 Azure DevOps 的克隆窗口中生成的。

现在,我的目标只是让这个脚本创建一个分支。最后,我想传入变量并使其更复杂。

最佳答案

我有点困惑为什么你需要这样的东西。

如果使用 pipeline.yaml 所在的相同存储库,您应该能够使用 git 命令,因为

- checkout: self
persistCredentials: true

如果您想 checkout 不同的存储库,请考虑使用服务连接多个存储库 选项进行 checkout :

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)

来源:Multiple repositories documentation

另请记住,多个存储库将更改默认存储库路径:

If you are using default paths, adding a second repository checkout step changes the default path of the code for the first repository. For example, the code for a repository named tools would be checked out to C:\agent_work\1\s when tools is the only repository, but if a second repository is added, tools would then be checked out to C:\agent_work\1\s\tools. If you have any steps that depend on the source code being in the original location, those steps must be updated.

关于azure-devops - 如何在 Azure DevOps 中使用 yaml 从管道运行 git 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66271214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com