DSL 是jenkins特有的语言,通过groovy来实现,可以通过流水线语法中的片段生成器来生成。
一、withCredentials方法调用凭据
1、通过片段生成器把凭据中的用户名/密码复制给变量并生成流水线脚本
withCredentials([usernamePassword(credentialsId: '6aee902f-68fe-46f3-943c-d91a0873862b', passwordVariable: 'password', usernameVariable: 'username')]) {
// some block
}
2、然后就可以在jenkinsfile中去调用这个用户名密码了
node{
withCredentials([usernamePassword(credentialsId: '6aee902f-68fe-46f3-943c-d91a0873862b', passwordVariable: 'password', usernameVariable: 'username')]) {
// some block
println(username)
println(password)
}
}
二、checkout 方法拉取代码
1、通过片段生成器生成DSL语法
2、这样就可以在pipeline中拉代码了(checkout支持git和svn)
pipeline {
agent any
stages {
stage('拉代码 ') {
steps {
//checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '6aee902f-68fe-46f3-943c-d91a0873862b', url: 'https://github.com/wenqiangqiang/jenkinslib.git']]])
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: '63447cba-701b-4156-a1cc-d8971063f988', url: 'https://gitee.com/wenqiangit/jenkinslib.git']]])
}
}
stage('构建') {
steps {
println('构建')
}
}
}
}