我只想从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中生成的。
现在,我的目标只是让这个脚本创建一个分支。最后,我想传递变量,使它更加复杂。
发布于 2021-02-19 09:12:21
在克隆Azure repos时单击"Generate凭据“选项后,您将看到下面的面板。

因此,您可以使用以下脚本为该存储库创建分支
git clone https://username:password@dev.azure.com/organization/project/_git/repository_name
cd repository_name
git checkout dev
git checkout -b newer-branch
git commit -a -m 'new branch commit'
git push --set-upstream origin newer-branch发布于 2021-02-19 21:23:10
我有点搞不懂你为什么需要这样的东西。
如果使用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\tools。如果有任何步骤依赖于原始位置上的源代码,则必须更新这些步骤。
发布于 2021-02-19 03:19:33
你在用SSH吗?如果是,那么我认为您必须创建一个SSH密钥身份验证,以便克隆到您的服务器。有关更多信息,您可以查看:https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops
https://stackoverflow.com/questions/66271214
复制相似问题