I am trying to push to a GitHub repository from Jenkins using
git remote set-url origin [email protected]:$reponame.git
git checkout $branch
git add file
git commit -m "Add file"
git push origin $branch
However I am getting the error:
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.
All the answers I've seen for solving this recommend using the Git Publisher Post Build Step. I am not able to use Git Publisher as I have multiple SCM defined which are defined by the $reponame variable.
I tried looking at the output of git show-ref
and this shows the list of branches that are part of the GitHub repo.
I'm not sure how to solve the above errors, any help on this issue would be greatly appreciated.
UPDATE:
I've been able to successfully push, however the changes are not reflected on the GitHub branch. When I check GitHub the commit is not added to the branch. When I run the job again, the push returns "Everything up to date" implying that the branch that it pushed to already has those changes.
Where is this Git push pushing to? And why are the changes not reflected on the remote GitHub branch?
How to Fix the error: failed to push some refs to Error in Git. We can fix the error: failed to push some refs to [remote repo] error in Git using the git pull origin [branch] or git pull --rebase origin [branch] commands. In most cases, the latter fixes the error.
Step 1: go to your GitHub repository and click on 'Settings'. Step 2: Click on Webhooks and then click on 'Add webhook'. Step 3: In the 'Payload URL' field, paste your Jenkins environment URL. At the end of this URL add /github-webhook/.
Note: The “fatal: 'origin' does not appear to be a git repository” error occurs when you try to push code to a remote Git repository without telling Git the exact location of the remote repository. To solve this error, use the git remote add command to add a remote to your project.
gitPush : Git Push. The git plugin provides fundamental git operations for Jenkins projects. It can poll, fetch, checkout, and merge contents of git repositories. The git plugin provides an SCM implementation to be used with the Pipeline SCM checkout step.
I would use Jenkins pipelines or Multibranch which allows you push in your repo without using the GitHub Publisher plugin. You have to create a Jenkinsfile in your repo and create the job follow the documentation. Then you have to options:
SSH as you are doing:
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>'
}
}
HTTPS as another response is suggesting:
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>'
}
}
As mentioned here, for a bitnami.com environment:
Could you please try to run
source /opt/bitnami/use_jenkins
before configure your Git repo in Jenkins: it will load all the needed env vars that you need.If you're usng a LAMP Stack, the script you're looking for will have the name
/opt/bitnami/use_lamp
Please note that the name of this script has the name
use_APPNAME
.
Depending on the Bitnami Stack you're using the placeholderAPPNAME
will be changed with the name of the app.
Also, double-check the nature of your SSH key (new OPENSSH format or old openssl PEM format)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With