Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when pushing to GitHub repository from Jenkins - cannot use Git Publisher

Tags:

git

jenkins

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?

like image 948
fuzzi Avatar asked Mar 14 '19 10:03

fuzzi


People also ask

How do I fix error failed to push some refs in GitHub?

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.

How do I push Jenkins files to GitHub?

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/.

How do you fix fatal origin does not appear to be a git repository?

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.

Is it possible to git merge push using Jenkins pipeline?

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.


2 Answers

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:

  1. 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>' 
            }
        }
    
  2. 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>'
            }
        }
    
like image 187
Carlos Cavero Avatar answered Oct 01 '22 20:10

Carlos Cavero


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 placeholder APPNAME 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)

like image 43
VonC Avatar answered Oct 01 '22 19:10

VonC