These are chat archives for jenkinsci/jenkins

19th
Feb 2018
Justin
@jgeorgeson
Feb 19 18:03
@nirtal85 have you looked at the checkout step?
Nir Tal
@nirtal85
Feb 19 18:05
@jgeorgeson what is the link to this step?
Rushikesh Jawali
@hrushie
Feb 19 18:09
@nirtal85 stages {
  stage('SCM') {

    steps{
      checkout([$class: 'GitSCM',
          branches: [[name: 'master']],
          doGenerateSubmoduleConfigurations: false,
          userRemoteConfigs: [[credentialsId: 'your id', url: 'https://github.com/nirtal85/AutomationExample.git']]])
        }
      }
this is simple checkout you can do, declarative pipeline.
Mark Waite
@MarkEWaite
Feb 19 19:10
@nirtal85 if you're using Declarative Pipeline in a multi-branch Pipeline, it performs an implicit checkout of the current branch. Thus, if the current branch is 'master', then the Declarative Pipeline in a multi-branch Pipeline will checkout the master. If you're using Scripted Pipeline, then "checkout scm" will checkout the current branch. The "Pipeline Syntax" link on most Pipeline job pages includes a helper for "checkout" that will provide a suggested checkout syntax using the options you select from the user interface.
Nir Tal
@nirtal85
Feb 19 22:16
@hrushie - does a checkout do a git pull?!
i read all the documentation but still confused - what is the equivalence for:
git checkout master git pull
Rushikesh Jawali
@hrushie
Feb 19 22:19
if you only need to pull the branch you have to use the shell script
Nir Tal
@nirtal85
Feb 19 22:19
i can't do a git pull using a pipeline?
Rushikesh Jawali
@hrushie
Feb 19 22:21
stage('Checkout') {
steps {
sh ''' Checkout commands '''
}
}
Mark Waite
@MarkEWaite
Feb 19 23:27
@nirtal85 the checkout scm step is implemented in the Jenkins git plugin as a git fetch followed by a git checkout of a specific SHA1 hash. Optionally, a step is added which performs a checkout to a named branch. What are you trying to accomplish that requires a git pull?
Nir Tal
@nirtal85
Feb 19 23:28
i want the latest code of branch master
Mark Waite
@MarkEWaite
Feb 19 23:29
@nirtal85 fetch and checkout will give you the latest code for the master branch. No need for a pull.
Nir Tal
@nirtal85
Feb 19 23:29

so should i use this:

stage('SCM') {

steps{
  checkout([$class: 'GitSCM',
      branches: [[name: 'master']],
      doGenerateSubmoduleConfigurations: false,
      userRemoteConfigs: [[credentialsId: 'your id', url: 'https://github.com/nirtal85/AutomationExample.git']]])
    }
  }

?

Mark Waite
@MarkEWaite
Feb 19 23:32
@nirtal85 https://jenkins.io/doc/pipeline/tour/hello-world/ shows that you don't need a checkout step in declarative Pipeline.
@nirtal85 yes, you can perform a checkout step from a declarative Pipeline, but that is generally only done if you need more than one git repository in your Pipeline workspace.
Mark Waite
@MarkEWaite
Feb 19 23:40
@nirtal85 the https://jenkins.io/doc/tutorials/ includes several different examples which may help you work through the steps you need in your Pipeline.
Nir Tal
@nirtal85
Feb 19 23:41
@MarkEWaite thanks. i will read!