步骤1:生成用户字符串
点击Pipeline Syntax
选择git:Git
或checkout:xxxxxx
,然后选择下方-none-
处已经添加的用户名跟密码,若未添加,则使用下方Add
进行添加
在下方使用Generate Pipeline Script
进行语法生成,如下:
生成的格式为:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
即为我们需要的用户字符串
步骤2:编写pipeline脚本
pipeline {
agent any
stages {
stage('Hello') {
steps {
checkout scmGit(branches: [[name: '*/main']], extensions: [submodule(parentCredentials: true, recursiveSubmodules: true, reference: '')], userRemoteConfigs: [[credentialsId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', url: 'http://192.168.0.1:8080/xxx/xxxxxxxxxx']])
withCredentials([
gitUsernamePassword(credentialsId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', gitToolName: 'Default')
]){
sh """
git branch
git checkout main
touch test.txt
echo "test" >> test.txt
git add test.txt
git commit -m "test"
git push origin main
"""
}
}
}
}
}
pipeline的使用案例可参考https://www.cnblogs.com/FRESHMANS/p/8184874.html
参考链接:
- https://www.saoniuhuo.com/question/detail-2324217.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)