gpt4 book ai didi

git - Jenkins 管道 ssh 代理 git push 失败

转载 作者:行者123 更新时间:2023-12-03 14:38:34 25 4
gpt4 key购买 nike

在我的 jenkins 管道中,我可以很好地克隆存储库,但使用 SSH 代理插件推回标签失败。我已经确保 github 上的部署 key 具有写访问权限,所以似乎还有一些其他问题......

pipeline {
agent { docker { image 'node:8' } }

stages {
stage('Pull Repo') {
steps {
git (
branch: 'master',
credentialsId: 'cred-id',
url: 'github.com:***'
)
sshagent(['github-omnia']) {
sh("git tag -a \"release-2.3.${BUILD_NUMBER}\" -m \"Jenkins built ${BUILD_NUMBER}\"")
sh("git push --tags")
}
}
}
}
}

我错过了什么吗?

编辑:
这是错误的控制台输出
[ssh-agent] Using credentials git (Access to Github-**)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
$ docker exec a6cee721d592b10bb94abbde0471d24a4320dcd07362affb1f18454d6ebe028d ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-TI7dNVoYszsC/agent.12
SSH_AGENT_PID=17
Running ssh-add (command line suppressed)
Identity added: /var/jenkins_home/workspace/Build-And-Deploy-***@tmp/private_key_7884642190516796613.key (/var/jenkins_home/workspace/Build-And-Deploy-***@tmp/private_key_7884642190516796613.key)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ git config --global user.email jenkins@***.se
[Pipeline] sh
+ git config --global user.name Jenkins
[Pipeline] sh
+ git remote set-url origin git@github.com:***/***
[Pipeline] sh
+ git tag -a release-2.3.3 -m Jenkins built 3
[Pipeline] sh
+ git push origin --tags
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

最佳答案

我正在寻找一种方法来做到这一点,而无需完全忽略主机验证,也无需修改我的 Jenkins 机器的 known_hosts因为我想使用docker。我最终得到了这样的结果:

  • 在 Jenkins 中,创建一个“Secret text”类型的新凭证(我们称之为 GITHUB_HOST_KEY ),并将其值设置为主机 key ,例如:

  • # gets the host for github and copies it. You can run this from
    # any computer that has access to github.com (or whatever your
    # git server is)
    ssh-keyscan github.com | clip
  • 在您的 Jenkinsfile 中,将字符串保存到 known_hosts使用前 sshagent .这是我的管道;它需要一个名为 master-v5 的分支并生成一个分支 master-v5-dist其中包含许多构建文件。
  • pipeline {
    agent { docker { image 'node:14' } }

    stages {
    stage('Checkout') {
    steps {
    git branch: 'master-v5',
    url: 'git@github.com:internetarchive/bookreader.git',
    credentialsId: 'YOUR_GH_CREDENTIALS'
    }
    }
    stage('Build') { steps { sh 'npm install && npm run build' } }
    stage('Push') {
    steps {
    sh 'git config user.email "foo@bar.com"'
    sh 'git config user.name "Mr. Foo Bar"'

    sh 'git add BookReader'
    sh 'git commit -m Build files [ci skip]'

    withCredentials([string(credentialsId: 'GITHUB_HOST_KEY', variable: 'GITHUB_HOST_KEY')]) {
    sh 'mkdir -p ~/.ssh && echo "$GITHUB_HOST_KEY" >> ~/.ssh/known_hosts'
    }
    sshagent (credentials: ['YOUR_GH_CREDENTIALS']) {
    sh 'git push -f origin HEAD:master-v5-dist'
    }
    }
    }
    }
    }

    这可确保您使用受信任的主机 key ,因为您在确定已连接到真正的 github.com 时获得了主机 key (大概)。

    关于git - Jenkins 管道 ssh 代理 git push 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59286287/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com