[英]Credential error getting when adding SVN checkout in Jenkins pipeline
I am trying to test each step by step for creating a Jenkins pipeline job. 我正在尝试逐步测试创建Jenkins管道作业的过程。 For that, I am trying to test with svn checkout first for my sample pipeline.
为此,我正在尝试首先为示例管道使用svn checkout进行测试。 And I added declarative pipeline and added the svn checkout step.
我添加了声明性管道并添加了svn checkout步骤。 But I am getting the error like following:
但是我收到如下错误:
svn: E215004: No more credentials or we tried too many times.
And I added my pipeline job like the following: 我添加了如下的管道作业:
pipeline
{
agent any
stages
{
stage ('Checkout')
{
steps
{
sh 'svn co http://192.168.16.174/repository/pipeline'
}
}
}
}
My observation 我的观察
According to my observation, I did not added the svn repository credentials here. 根据我的观察,我没有在此处添加svn存储库凭据。 I am new to Jenkins and CI/CD.
我是Jenkins和CI / CD的新手。 When I learning I saw that we can create credentials in Jenkins and can refer that ID here.
在学习时,我看到我们可以在Jenkins中创建凭据,并且可以在此处引用该ID。 But I did not got exactly how to add.
但是我没有确切的添加方法。 Also another thing is that, I planned to add this in a Jenkinsfile which is storing in repository root directory.
还有另一件事是,我计划将其添加到存储在存储库根目录中的Jenkinsfile中。
My confusion 我的困惑
I have here lot of confusions related with credentials inside Jenkinsfile. 我在这里与Jenkinsfile中的凭证有关的很多困惑。 Please correct me if I went in wrong direction.
如果我走错了方向,请纠正我。
After little bit exploration I found that , Need to use the "withCredentials" option from jenkins to bind the created credentials to a uername and password variable. 经过一番探索,我发现,需要使用jenkins的“ withCredentials”选项将创建的凭证绑定到uername和password变量。 After binding in the stage steps , need to use the username and password variable with the SVN repository URL that we are going to hit using 'sh' command.
在阶段步骤中进行绑定之后,需要将用户名和密码变量与我们要使用“ sh”命令访问的SVN存储库URL一起使用。 Let me add what I did here ,
让我补充一下我在这里所做的事情
pipeline
{
agent any
stages
{
stage ('Checkout')
{
steps
{
withCredentials([[$class: 'UsernamePasswordMultiBinding',
credentialsId: '<credential-ID>',
usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
sh "svn co url --username $USERNAME --password $PASSWORD"
}
}
}
}
}
And will get the output like the following in the console like the following form, 并在控制台中获得如下形式的输出,如下所示:
Started by user admin
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node (hide)
Running on Jenkins in /var/lib/jenkins/workspace/kubernetes
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Checkout)
[Pipeline] withCredentials
Masking only exact matches of $USERNAME or $PASSWORD
[Pipeline] {
[Pipeline] sh
+ svn co 'url' --username **** --password ****
Checked out revision 1.
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.