【发布时间】:2022-11-09 09:42:20
【问题描述】:
要求是我需要将 gitlab 上的存储库镜像到天蓝色,保留所有历史记录。 我已经找到了一个脚本来执行此操作,并且在我的本地执行时它可以完美运行。 但是,我们想安排它,因此我们计划创建一个 jenkins 作业。
gitlab 的凭据在 jenkins 服务器上设置,ssh 密钥身份验证也在 jenkins 服务器和将触发管道的机器之间设置(我在我们网络中的 linux 服务器上运行管道,私有 SSH 密钥存储在 jenkins 上,SSH 公钥配置在 azure devops 平台上)
jenkins 脚本如下所示:`
pipeline {
agent {label 'linuxNode'}
stages {
stage('mirror to azure') {
steps {
withCredentials([
gitUsernamePassword(credentialsId: 'KEY', gitToolName: 'Default'),
sshUserPrivateKey(credentialsId: 'KEY', keyFileVariable: '')]) {
sh '''#!/bin/bash
set -eufo pipefail
SOURCE_URL="https://gitlab-XXXXX.de/X/X/X/X/Y"
echo "source url taken"
TARGET_URL="git@ssh.dev.azure.com:v3/XXXX-XX/XX%20XX%20VV%20ZZ/XYXYX"
echo "target url taken"
WORKDIR="$(mktemp -d)"
echo "Cloning from ${SOURCE_URL} into ${WORKDIR}..."
git init --bare "${WORKDIR}"
cd "${WORKDIR}"
git config remote.origin.url "${SOURCE_URL}"
git config --add remote.origin.fetch '+refs/heads/*:refs/heads/*'
git config --add remote.origin.fetch '+refs/tags/*:refs/tags/*'
git config --add remote.origin.fetch '+refs/notes/*:refs/notes/*'
git config remote.origin.mirror true
echo "we are before remote fetch"
git fetch --all
echo "we are after remote fetch"
echo ""
echo "Cloned to ${WORKDIR}; pushing to ${TARGET_URL}"
git config http.proxy http://XXXX.XXXXX.XX:0000
git push --mirror "${TARGET_URL}"
echo ""
echo "Cleaning up temporary directory ${WORKDIR}..."
rm -rf "${WORKDIR}"
echo "Done."
'''
}
}
}
}
}
但是在 push 命令之后我最终得到了一个错误。错误:
15:33:47 Cloned to /tmp/tmp.pFdLWmf3rc; pushing to git@ssh.dev.azure.com:v3/XXXX-XX/XX%20XX%20VV%20ZZ/XYXYX
15:34:19 kex_exchange_identification: read: Connection reset by peer
15:34:19 fatal: Could not read from remote repository.
15:34:19 15:34:19 Please make sure you have the correct access rights
15:34:19 and the repository exists.
15:34:19 [Pipeline] }
15:34:19 [Pipeline] // withCredentials
15:34:19 [Pipeline] }
15:34:19 [Pipeline] // stage
15:34:19 [Pipeline] }
15:34:19 [Pipeline] // node
15:34:19 [Pipeline] End of Pipeline
15:34:19 ERROR: script returned exit code 128
【问题讨论】:
-
它说检查访问权限。您是否检查过您使用的凭据是否有效以及 GitLab 是否可以访问您的 Azure 实例?
标签: azure jenkins azure-devops gitlab azure-repos