tabeyti / jenkins-jack

Jack into your Jenkins to execute Pipeline scripts, provide Pipeline step autocompletions, pull Shared Library step documenation, run console groovy scripts across multiple nodes, and more! Honestly, not that much more.
Other
98 stars 31 forks source link

'checkout scm' does not work when ran in pipeline script #55

Closed pellet closed 3 years ago

pellet commented 3 years ago

I'm trying to execute a script from inside jenkins jack, the script runs ok on jenkins itself, but when I try inside of vscode I get:

ERROR: ‘checkout scm’ is only available when using “Multibranch Pipeline” or “Pipeline script from SCM” Any ideas how to fix this?

pellet commented 3 years ago

I figured out how to get around this.. just had to use the jenkins snippet generator to generate some groovy code for checking out the repository, it ended up looking a bit like this: checkout([ $class: 'GitSCM', branches: [[name: '*/develop']], doGenerateSubmoduleConfigurations: false, extensions: [[ $class: 'SubmoduleOption', depth: 1, disableSubmodules: false, parentCredentials: true, recursiveSubmodules: true, reference: '', shallow: true, trackingSubmodules: false], [$class: 'GitLFSPull']], submoduleCfg: [], userRemoteConfigs: [[ credentialsId: '$creds', url: '$repo']]]);

medguywalker commented 3 years ago

Pretty Print:

because after a long day of Jenkins, anything helps. @pellet - thank you btw, I had to remove [$class: 'GitLFSPull'] to make this work but works perfect

checkout([ 
  $class: 'GitSCM', 
  branches: [[name: '*/develop']], 
  doGenerateSubmoduleConfigurations: false, 
  extensions: [
    [ 
      $class: 'SubmoduleOption', 
      depth: 1, 
      disableSubmodules: false, 
      parentCredentials: true, 
      recursiveSubmodules: true, 
      reference: '', 
      shallow: true, 
      trackingSubmodules: false
    ], 
    [$class: 'GitLFSPull']
  ], 
  submoduleCfg: [], 
  userRemoteConfigs: [[ credentialsId: '$creds', url: '$repo']]
]);
ni-dschiller commented 2 years ago

Where did you place the checkout method or how did you use it ?

ogtlimited commented 1 year ago

Where did you place the checkout method or how did you use it ?

very important question. because I am attempting to use but not even getting any output

pellet commented 1 year ago

Try using the jenkins snippet generator as I had mentioned above, it may help with you debugging the checkout function.

medguywalker commented 1 year ago

@ni-dschiller @ogtlimited - if been wrecked with work but here is an update, paying it forward @pellet - note: the original solution didn't handle git tags well but I hacked on it a bit and this is running smooth for me, thanks again

Declarative Pipeline Example - https://gist.github.com/medguywalker/8816de7a98ddd437011677c239d65cf7 Scripted Pipeline Example - https://gist.github.com/medguywalker/e2beac3b352b0cd939f7c7b4c95a7b08