Azure Pipeline maven release:perform 失败 "The git-clone command failed."
Azure Pipeline maven release:perform fails with "The git-clone command failed."
目前,我尝试构建一个 spring 引导应用程序并使用 Azure Pipelines 和 maven-release-plugin 进行发布。
我的 Azure 管道 YAML 如下所示:
- 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***
我还添加了 Allow Contriubte、Create branch、Create tag 和 Read 权限 Project Collection Build Service (MyCompany) 在 Azure Dev Ops Project Settings -> Repositories -> - > 安全
因此在执行 release:perform 的最后一个 task 之前一切正常
显示的错误是:
[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
谁能指出我哪里做错了?
之后,git标签被构建并提交到SCM
更新
我尝试在批处理内联脚本中执行 Maven 在发布执行中尝试执行的操作,并且它有点奏效。现在我更糊涂了。
- 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
输出为:
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
好的,我找到了一个解决方案,涉及使用 Azure DevOps Git SSH URL 而不是 HTTPS。
首先,我根据这个Use SSH key authentication或者选择你们的Git供应商教程创建了一个SSH Key。
获得 SSH 私钥和 public 密钥后,您需要将 SSH 密钥安装到 YAML 管道中。参见 Install SSH Key task。
- task: InstallSSHKey@0
inputs:
knownHostsEntry: ssh.dev.azure.com ssh-rsa <YOUR KNOWN HOST KEY>
sshKeySecureFile: <NameOfSecureFileKey>
sshPassphrase: <PassphraseIfUsed>
以下是总结的步骤
在您的 .ssh 文件夹中使用私钥 azurePipeline
和 public 私钥创建一个密钥对 azurePipeline.pub
(如果需要,输入密码)
ssh-keygen -f ~.ssh/azurePipeline -t rsa
获取已知主机条目,例如ssh.dev.azure.com ssh-rsa AAAAB3Nz....
和
ssh-keyscan ssh.dev.azure.com
转到 Azure DevOps 并添加 public 密钥的内容,如 Use SSH key authentication
中所述
将私钥添加为安全文件,如 Install SSH Key task
中所述
将 SCM 网址 pom.xml 更改为:
一个
<scm>
<developerConnection>scm:git:git@ssh.dev.azure.com:v3/kiongroup/CxP/myaccount-service</developerConnection>
<tag>HEAD</tag>
</scm>
希望这对外面的人有帮助:)
我能够在不使用 SSH 身份验证的情况下解决上述问题。通过将组织名称指定为用户名并将 SystemAccessToken 指定为密码,release:perform 能够 运行 成功:
- task: Maven@3
displayName: Perform release
inputs:
mavenPomFile: 'pom.xml'
options: '-Dusername="<name of your DevOps organisation>" -Dpassword="$(System.AccessToken)"'
目前,我尝试构建一个 spring 引导应用程序并使用 Azure Pipelines 和 maven-release-plugin 进行发布。
我的 Azure 管道 YAML 如下所示:
- 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***
我还添加了 Allow Contriubte、Create branch、Create tag 和 Read 权限 Project Collection Build Service (MyCompany) 在 Azure Dev Ops Project Settings -> Repositories -> - > 安全
因此在执行 release:perform 的最后一个 task 之前一切正常 显示的错误是:
[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
谁能指出我哪里做错了?
之后,git标签被构建并提交到SCM
更新 我尝试在批处理内联脚本中执行 Maven 在发布执行中尝试执行的操作,并且它有点奏效。现在我更糊涂了。
- 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
输出为:
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
好的,我找到了一个解决方案,涉及使用 Azure DevOps Git SSH URL 而不是 HTTPS。
首先,我根据这个Use SSH key authentication或者选择你们的Git供应商教程创建了一个SSH Key。
获得 SSH 私钥和 public 密钥后,您需要将 SSH 密钥安装到 YAML 管道中。参见 Install SSH Key task。
- task: InstallSSHKey@0
inputs:
knownHostsEntry: ssh.dev.azure.com ssh-rsa <YOUR KNOWN HOST KEY>
sshKeySecureFile: <NameOfSecureFileKey>
sshPassphrase: <PassphraseIfUsed>
以下是总结的步骤
在您的 .ssh 文件夹中使用私钥
azurePipeline
和 public 私钥创建一个密钥对azurePipeline.pub
(如果需要,输入密码)ssh-keygen -f ~.ssh/azurePipeline -t rsa
获取已知主机条目,例如
ssh.dev.azure.com ssh-rsa AAAAB3Nz....
和ssh-keyscan ssh.dev.azure.com
转到 Azure DevOps 并添加 public 密钥的内容,如 Use SSH key authentication
中所述将私钥添加为安全文件,如 Install SSH Key task
中所述将 SCM 网址 pom.xml 更改为:
一个
<scm>
<developerConnection>scm:git:git@ssh.dev.azure.com:v3/kiongroup/CxP/myaccount-service</developerConnection>
<tag>HEAD</tag>
</scm>
希望这对外面的人有帮助:)
我能够在不使用 SSH 身份验证的情况下解决上述问题。通过将组织名称指定为用户名并将 SystemAccessToken 指定为密码,release:perform 能够 运行 成功:
- task: Maven@3
displayName: Perform release
inputs:
mavenPomFile: 'pom.xml'
options: '-Dusername="<name of your DevOps organisation>" -Dpassword="$(System.AccessToken)"'