使用 Azure DevOps Pipeline 将文件推送到存储库

问题描述 投票:0回答:1

我有一个天蓝色的 DevOps 管道,可以使用以下命令检查两个存储库

resources:
  repositories:
    - repository: 'essentials'
      type : 'git'
      name : 'ic-essentials'
steps:
- checkout: self
  persistCredentials: true
- checkout: 'essentials'

注意

essentials
是与
self
不同的存储库。

稍后它会在

essentials
存储库中使用以下模板化管道创建一个文件,

parameters:  
  - name: SolutionName
    type: string
    displayName: 'Name of the Solution to be saved'
  - name: Version
    type: string
    displayName: 'Semver version of the solution'
  - name: CoreRepository
    type: string
    displayName: 'Name of the core repository'

steps:
- task: PowerShell@2
  displayName: 'Setting git default'
  inputs:    
    targetType: 'inline'
    script: |      
      git config --global user.email $(Git.UserEmail)
      git config --global user.name $(Git.UserName)     
           

- task: PowerShell@2
  displayName: 'Create manifest'
  inputs:
    targetType: 'inline'
    script: |
        Write-Host "Logic for manifest creation is loaded"
        # A logic that creates a file in the following location
        # $(Build.SourcesDirectory)/${{parameters.CoreRepository}}/Manifest

- task: PowerShell@2
  displayName: 'Committing files and pushing'
  inputs:    
    targetType: 'inline'
    script: |      
      Set-Location -Path $(Build.SourcesDirectory)/${{parameters.CoreRepository}}      
      git push --set-upstream origin main
      git add .
      git commit -m "Committing the manifest file"
      git push origin HEAD:main

我收到以下错误,

error: src refspec main does not match any
error: failed to push some refs to 'https://dev.azure.com/MyOrg/MyProj/_git/MyRepo'
[detached HEAD f327404] Committing the manifest file
 1 file changed, 8 insertions(+)
 create mode 100644 Manifest/THEFILE.manifest.xml
fatal: could not read Password for 'https://[email protected]': terminal prompts disabled
##[error]PowerShell exited with code '1'.

我可以确认

  • 存储库存在。还有分支
    main
  • 该文件肯定是在规定的位置创建的。
  • 代理
    My Project Build Service (My Org)
    作为贡献者访问存储库。

我仍然认为这与代理对存储库的访问权限有关。我是否忽略了一些显而易见的事情?

git azure powershell azure-pipelines checkout
1个回答
0
投票

您可以使用一个小脚本来处理凭据:

- task: PowerShell@2
  displayName: 'Committing files and pushing'
  inputs:    
    targetType: 'inline'
    script: |      
      git config --global credential. Helper "!f() { echo \`"username=.`npassword=`${TOKEN}\`"; }; f"
      Set-Location -Path $(Build.SourcesDirectory)/${{parameters.CoreRepository}}      
      git push --set-upstream origin main
      git add .
      git commit -m "Committing the manifest file"
      git push origin HEAD:main
  env:
    TOKEN: $(System.AccessToken)
© www.soinside.com 2019 - 2024. All rights reserved.