1

I'm trying to set up the credentials for github in a jenkins pipeline job. I have the following in my pipeline script:

pipeline {
    agent any
    git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])

Where does the credentialsId come from? Is this created elsewhere in Jenkins?

Update: I pulled the credentials id from this page: enter image description here

But now I am seeing this error:

Started by user anonymous org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: WorkflowScript: 3: Undefined section "git" @ line 3, column 5.

opike
  • 7,053
  • 14
  • 68
  • 95

1 Answers1

3

As you found yourself, it's the credentials id provided in the credentials view.

Now, as for your second problem, you're using declarative pipeline, it requires that you have the following structure:

pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
            }
        }
    }
}

E.g. you need to put the git step insde of the stages, stage and steps clauses (documentation of this can be found here).

Alternatively you can use scripted pipeline, then it becomes:

node {
    git([url: 'ssh://git@github.com/user/repname/', branch: 'master', credentialsId: 'xxx-xxx-xxx'])
}

However, when you're creating simple pipelines, then declarative pipelines provides a lot of nice to have features. See my answer here for a comparison between declarative and scripted pipelines.

Community
  • 1
  • 1
Jon S
  • 15,846
  • 4
  • 44
  • 45