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

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

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

Yannick Lacaute

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

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

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 {
    timeout(time: 15, unit: 'MINUTES')
    buildDiscarder(logRotator(numToKeepStr: '10', artifactNumToKeepStr: '10'))
  environment {
    GITLAB_CREDENTIALS = credentials('home-build-gitlab-ci-writer')
  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:[hidden email]/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