I can get almost all git informations i need, whether from env variables, or by git commands or using checkoutInfo = checkout scm . The only thing i dont know how to get is credentials id used in jobs settings (those in ‘Credentials’ field) which are used for default check out. Whether it is user-password or key. I it possible to somehow get this string? Maybe some additional plugin?
So far im using these (the ones relevant to topic): git, git client github, Gitbub Branch Source, Bitbucket branch source, pipeline,
Its VERY hard to google this topic because results only show solutions for using fixed credentials in GitSCM.
You’re very close with those. For historical reasons, the git plugin userRemoteConfig is a list of configurations rather than a single configuration. The Pipeline Syntax Snippet Generator at .../pipeline-syntax shows you that when you press the “Add” button to add another repository to the list of repositories.
You want scm.userRemoteConfig[0].credentialsId.
I don’t think there are very many useful cases where a remote configuration should be a list, since all of the repositories in the list are assumed to have shared history. However, we don’t want to break compatibility for those users who depend on it being a list, so it remains a list.
Are you sure that you are using a credential in that checkout? I inserted the following into my Bitbucket branch source test case and it reported the expected values:
07:37:17 scm userRemoteConfigs.url is git@bitbucket.org:markewaite/jenkins-bugs.git
07:37:17 scm userRemoteConfigs.refspec is +refs/heads/JENKINS-39905:refs/remotes/origin/JENKINS-39905
07:37:17 scm userRemoteConfigs.credentialsId is jenkins-bugs-repo-scan-password-bitbucket
I switched my Bitbucket multibranch Pipeline example to checkout scm. I see a value for credentialsId. The job definition with checkout scm reports the credential used for the checkout. The output looks like this:
11:34:10 [Pipeline] echo
11:34:10
11:34:10 scm userRemoteConfigs is +refs/heads/JENKINS-39905:refs/remotes/origin/JENKINS-39905 => git@bitbucket.org:markewaite/jenkins-bugs.git (origin)
11:34:10 scm userRemoteConfigs.url is git@bitbucket.org:markewaite/jenkins-bugs.git
11:34:10 scm userRemoteConfigs.refspec is +refs/heads/JENKINS-39905:refs/remotes/origin/JENKINS-39905
11:34:10 scm userRemoteConfigs.credentialsId is markewaite-bitbucket-rsa-private-key
11:34:10
11:34:10 [Pipeline] }
Maybe you’re not using a multibranch Pipeline but some other form of Pipeline job?