How to commit and push in a declartive pipeline with auto-checkout ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to commit and push in a declartive pipeline with auto-checkout ?

Yannick Lacaute
Hi,

I have this error when I try to commit & push in a pipeline :

11:22:35
 error: src refspec master does not match any.
11:22:35 error: failed to push some refs to 'http://****@foo.net/bar.git'

If I click on the url, I go in my project, so the url is correct. It is not an empty repository at all, and I have commited something. All solutions read on Internet do not speak about my situation.

I am pretty sure it is about the way the project is checkouted by the declarative pipeline, which implies a different git command to push.


Example pipeline :

pipeline {
  agent {
    label 'master'
  }
  options {
    timestamps()
    timeout(time: 15, unit: 'MINUTES')
    buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
  }
  stages {
    stage('Test') {
      steps {
        sh "git rev-parse HEAD" // show me last commit
        sh "touch toto"
        sh "git add ."
        sh "git commit -m \'test commit\'"
        sh "git rev-parse HEAD" // show me new last commit
        script {
          def secureUrl = "http://usr:p...@.../bar.git}"
       
          // do not work
          sh "git push ${secureUrl} master"

          // do not work either
          sh "git push ${secureUrl} origin HEAD:master"
        }
      }
    }
  }
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b80bc104-e238-408c-a865-9fc5b68ee35cn%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to commit and push in a declartive pipeline with auto-checkout ?

Yannick Lacaute
Ok found it :

git push --set-upstream repoUrl HEAD:<BRANCH>


Le dimanche 20 décembre 2020 à 11:45:43 UTC+1, Yannick Lacaute a écrit :
Hi,

I have this error when I try to commit & push in a pipeline :

11:22:35
 error: src refspec master does not match any.
11:22:35 error: failed to push some refs to 'http://****@foo.net/bar.git'

If I click on the url, I go in my project, so the url is correct. It is not an empty repository at all, and I have commited something. All solutions read on Internet do not speak about my situation.

I am pretty sure it is about the way the project is checkouted by the declarative pipeline, which implies a different git command to push.


Example pipeline :

pipeline {
  agent {
    label 'master'
  }
  options {
    timestamps()
    timeout(time: 15, unit: 'MINUTES')
    buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
  }
  stages {
    stage('Test') {
      steps {
        sh "git rev-parse HEAD" // show me last commit
        sh "touch toto"
        sh "git add ."
        sh "git commit -m \'test commit\'"
        sh "git rev-parse HEAD" // show me new last commit
        script {
          def secureUrl = "http://usr:p...@.../bar.git}"
       
          // do not work
          sh "git push ${secureUrl} master"

          // do not work either
          sh "git push ${secureUrl} origin HEAD:master"
        }
      }
    }
  }
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/69c26213-dc7e-4f27-9468-89918061187en%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: How to commit and push in a declartive pipeline with auto-checkout ?

Yannick Lacaute
git push --set-upstream repoUrl branch  

Le dimanche 20 décembre 2020 à 12:24:16 UTC+1, Yannick Lacaute a écrit :
Ok found it :

git push --set-upstream repoUrl HEAD:<BRANCH>


Le dimanche 20 décembre 2020 à 11:45:43 UTC+1, Yannick Lacaute a écrit :
Hi,

I have this error when I try to commit & push in a pipeline :

11:22:35
 error: src refspec master does not match any.
11:22:35 error: failed to push some refs to 'http://****@foo.net/bar.git'

If I click on the url, I go in my project, so the url is correct. It is not an empty repository at all, and I have commited something. All solutions read on Internet do not speak about my situation.

I am pretty sure it is about the way the project is checkouted by the declarative pipeline, which implies a different git command to push.


Example pipeline :

pipeline {
  agent {
    label 'master'
  }
  options {
    timestamps()
    timeout(time: 15, unit: 'MINUTES')
    buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
  }
  stages {
    stage('Test') {
      steps {
        sh "git rev-parse HEAD" // show me last commit
        sh "touch toto"
        sh "git add ."
        sh "git commit -m \'test commit\'"
        sh "git rev-parse HEAD" // show me new last commit
        script {
          def secureUrl = "http://usr:p...@.../bar.git}"
       
          // do not work
          sh "git push ${secureUrl} master"

          // do not work either
          sh "git push ${secureUrl} origin HEAD:master"
        }
      }
    }
  }
}

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/b0de1483-4c62-469f-9ef6-40c74f2060c7n%40googlegroups.com.