赞
踩
点击Pipeline Syntax
选择git:Git
或checkout:xxxxxx
,然后选择下方-none-
处已经添加的用户名跟密码,若未添加,则使用下方Add
进行添加
在下方使用Generate Pipeline Script
进行语法生成,如下:
生成的格式为:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
即为我们需要的用户字符串
pipeline { agent any stages { stage('Hello') { steps { # 拉取xxxxxxxxxx仓库代码, 并拉取子仓库代码 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']]) # 使用credentialsId操作git, 与终端操作相同, 注意语句要在sh ''中执行 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
参考链接:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。