首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Azure管道maven发行版:使用“git-clone命令失败”执行失败。

Azure管道maven发行版:使用“git-clone命令失败”执行失败。
EN

Stack Overflow用户
提问于 2022-02-01 19:47:12
回答 2查看 456关注 0票数 3

目前,我尝试构建一个spring引导应用程序,并使用Azure管道和maven发布插件发布版本。

我的Azure管道YAML是这样的:

代码语言:javascript
复制
- stage: BuildRelease
  condition: true
  displayName: Building a Release with Maven
  jobs: 
    - job: BuildReleaseJob
      displayName: Create a Maven release with version $(releaseVersion)
      steps:
      - checkout: self
        persistCredentials: true
        
      - task: MavenAuthenticate@0
        displayName: 'Authenticate to Maven'
        inputs:
          artifactsFeeds: 'ciam'

      - task: Bash@3
        displayName: Set Git Credentials
        inputs:
          targetType: 'inline'
          script: |
            git config --global user.email "you@example.com"
            git config --global user.name "Azure Pipeline Release"
            git checkout develop

       - task: Bash@3
         displayName: Maven Clean & Prepare Release
         inputs:
           targetType: 'inline'
           script: |
             mvn --batch-mode release:clean release:prepare -DscmCommentPrefix=***NO_CI***

      - task: Bash@3
        displayName: Maven  Perform Release
        inputs:
          targetType: 'inline'
          script: |
            mvn --batch-mode release:perform -DscmCommentPrefix=***NO_CI***

我还添加了允许 Contriubte、创建分支、创建标记和读取项目集合构建服务(MyCompany)在Azure Dev 项目设置中的权限 -> 存储库 -> -> SecuirtyE 210

因此,在执行发行版的上一次任务之前,一切都正常:执行显示的错误是:

代码语言:javascript
复制
[INFO] Executing: /bin/sh -c cd /home/vsts/work/1/s/target && git clone --branch projectName-0.0.36 https:********@dev.azure.com/MyCompany/Project/_git/projectName-service /home/vsts/work/1/s/target/checkout
[INFO] Working directory: /home/vsts/work/1/s/target
[ERROR] The git-clone command failed.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.136 s
[INFO] Finished at: 2022-02-01T14:18:31Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5.3:perform (default-cli) on project projectName-service: Unable to checkout from SCM
[ERROR] Provider message:
[ERROR] The git-clone command failed.
[ERROR] Command output:
[ERROR] Cloning into '/home/vsts/work/1/s/target/checkout'...
[ERROR] fatal: could not read Password for 'https://mycompany@dev.azure.com': terminal prompts disabled
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

有人能指出我做错了什么地方吗?

然后,在SCM中构建并提交git标记。

更新,我试图在批处理内联脚本中执行maven在发行版执行中所做的工作,它是起作用的。现在我更困惑了。

代码语言:javascript
复制
    - task: Bash@3
      displayName: TestClone
      inputs:
        targetType: inline
        script: |
          ls -laf /home/vsts/work/1/s/target/checkout
          /bin/sh -c cd '/home/vsts/work/1/s/target' && 'git' 'clone' '--depth' '1' '--branch' 'myaccount-service-0.0.43' 'https://$(System.AccessToken)@dev.azure.com/kiongroup/CxP/_git/myaccount-service' 'checkout'
          cd /home/vsts/work/1/s/target/checkout
          ls

产出如下:

代码语言:javascript
复制
ls: cannot access '/home/vsts/work/1/s/target/checkout': No such file or directory
Cloning into 'checkout'...
Note: switching to '1653266b5f151fd6137b7b579044eef1867d8d5b'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

/home/vsts/work/_temp/358629de-4b6b-4548-942e-f9a05281c5a5.sh: line 3: cd: /home/vsts/work/1/s/target/checkout: No such file or directory
Dockerfile
README.md
azure-pipelines.yml
checkout
docker
mvnw
mvnw.cmd
pom.xml
pom.xml.releaseBackup
postman
release.properties
src
target
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-02-09 08:01:21

好的,我找到了一个解决方案,它涉及到使用Azure DevOps Git SSH,而不是HTTPS。

首先,我根据这个使用SSH密钥身份验证创建了一个SSH密钥,或者选择Git提供者教程。

拥有SSH私钥和公钥后,需要将SSH密钥安装到YAML管道中。见安装SSH密钥任务

代码语言:javascript
复制
    - task: InstallSSHKey@0
      inputs:
        knownHostsEntry: ssh.dev.azure.com ssh-rsa <YOUR KNOWN HOST KEY>
        sshKeySecureFile: <NameOfSecureFileKey>
        sshPassphrase: <PassphraseIfUsed>

以下是总结的步骤

  1. 在您的KeyPair文件夹中创建一个.ssh文件夹,其中包含一个私钥azurePipeline和一个公共密钥azurePipeline.pub (如果需要,输入密码) ssh-keygen -f ~.ssh/azurePipeline -t rsa
  2. 获取已知的主机条目,例如ssh.dev.azure.com ssh-rsa AAAAB3Nz....和 键扫描ssh.dev.azure.com
  3. 转到Azure DevOps并添加使用SSH密钥身份验证中描述的公钥内容
  4. 将私钥添加为安全文件,如安装SSH密钥任务中所述
  5. 将SCM Urlin pom.xml更改为:

一个

代码语言:javascript
复制
<scm>
    <developerConnection>scm:git:git@ssh.dev.azure.com:v3/kiongroup/CxP/myaccount-service</developerConnection>
    <tag>HEAD</tag>
</scm>

希望这能对外面的人有所帮助

票数 0
EN

Stack Overflow用户

发布于 2022-03-18 10:34:26

我能够在不使用SSH身份验证的情况下修复上面描述的问题。通过将组织名称指定为用户名,将SystemAccessToken指定为密码,版本:perform能够成功运行:

代码语言:javascript
复制
- task: Maven@3
  displayName: Perform release
  inputs:
    mavenPomFile: 'pom.xml'
    options: '-Dusername="<name of your DevOps organisation>" -Dpassword="$(System.AccessToken)"'
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70946651

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档