[英]Jenkins Declarative Pipeline throws NullPointerException when I use withCredentials
I have a small pipeline that performs some GIT actions. 我有一个执行某些GIT动作的小型管道。 I'm trying to use ssh as the protocol to communicate, so I defined the private key in the JenkinsServer and I have everything working fine.
我正在尝试使用ssh作为通信协议,因此我在JenkinsServer中定义了私钥,并且一切正常。
stage('Some Stage'){
steps{
withCredentials([[$class: 'SSHUserPrivateKeyBinding', credentialsId: "${params.credentialsId}", usernameVariable: 'GIT_USERNAME']]){
script{
// Do some git operations...
}
}
}
If I remove the withCredentials from here the code works as fine, but I have to set the username hard coded in the git push commands. 如果我从此处删除withCredentials,代码可以正常工作,但是我必须设置git push命令中硬编码的用户名。 I want to fetch the username from the credentials instead.
我想从凭据中获取用户名。 but my jenkins always throws a NPE without any other message.
但是我的詹金人总是抛出NPE而没有其他消息。
I'm totally lost in this 我完全迷失了
Try the below and see if it helps. 请尝试以下操作,看看是否有帮助。 You can then refer username from credentials using
GIT_CREDENTIALS_USR
and password using GIT_CREDENTIALS_PSW
然后,您可以使用
GIT_CREDENTIALS_USR
从凭据引用用户名,并使用GIT_CREDENTIALS_PSW
GIT_CREDENTIALS_USR
密码
stage('Some Stage'){
environment {
GIT_CREDENTIALS = credentials('<credentialsID>')
}
steps{
script{
// Do some git operations...
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.