我正在尝试使用 Jenkins 从 GitHub 推送到存储库
git remote set-url origin git@github.com:$reponame.git
git checkout $branch
git add file
git commit -m "Add file"
git push origin $branch
Run Code Online (Sandbox Code Playgroud)
但是我收到错误:
ssh: /opt/bitnami/common/lib/libcrypto.so.1.0.0: no version information available (required by ssh)
ssh: /opt/bitnami/common/lib/libcrypto.so.1.0.0: no version information available (required by ssh)
Host key verification failed.
Run Code Online (Sandbox Code Playgroud)
我见过的解决此问题的所有答案都建议使用 Git Publisher 构建后步骤。我无法使用 Git Publisher,因为我定义了多个 SCM,这些 SCM 由 $reponame 变量定义。
我尝试查看输出git show-ref,这显示了 GitHub 存储库一部分的分支列表。
我不确定如何解决上述错误,对此问题的任何帮助将不胜感激。
更新:我已经能够成功推送,但是更改并未反映在 GitHub 分支上。当我检查 GitHub 时,提交未添加到分支中。当我再次运行该作业时,推送返回“一切都是最新的”,这意味着它推送到的分支已经有了这些更改。
这个 Git Push 推送到哪里了?为什么这些更改没有反映在远程 GitHub 分支上?
我会使用 Jenkins pipelines或Multibranch,它允许您在不使用 GitHub Publisher 插件的情况下推送您的存储库。您必须在存储库中创建Jenkinsfile并按照文档创建作业。然后你必须选择:
SSH 就像你正在做的那样:
stage('Preparation') {
// Get some code from the branch sending the webhook in GitHub
git 'your git repo'
}
stage('Build') {
// Do some stuff here
}
stage('Push') {
// Commit and push with ssh credentials
sshagent (credentials: ['your credentials']) {
sh "git commit -am 'Commit message'"
sh 'git push origin HEAD:<yourbranch>'
}
}
Run Code Online (Sandbox Code Playgroud)HTTPS 作为另一个响应建议:
stage('Preparation') {
// Get some code from the branch sending the webhook in GitHub
git 'your https repo'
}
stage('Build') {
// Do some stuff here
}
stage('Push') {
// Commit and push with ssh credentials
withCredentials(
[string(credentialsId: 'git-email', variable: 'GIT_COMMITTER_EMAIL'),
string(credentialsId: 'git-account', variable: 'GIT_COMMITTER_ACCOUNT'),
string(credentialsId: 'git-name', variable: 'GIT_COMMITTER_NAME'),
string(credentialsId: 'github-token', variable: 'GITHUB_API_TOKEN')]) {
// Configure the user
sh 'git config user.email "${GIT_COMMITTER_EMAIL}"'
sh 'git config user.name "${GIT_COMMITTER_NAME}"'
sh "git remote rm origin"
sh "git remote add origin https://${GIT_COMMITTER_ACCOUNT}:${GITHUB_API_TOKEN}@yourrepo.git > /dev/null 2>&1"
sh "git commit -am 'Commit message'"
sh 'git push origin HEAD:<yourbranch>'
}
}
Run Code Online (Sandbox Code Playgroud)