步驟1:生成用戶字符串
點擊Pipeline Syntax
選擇git:Git
或checkout:xxxxxx
,然后選擇下方-none-
處已經(jīng)添加的用戶名跟密碼,若未添加,則使用下方Add
進行添加
在下方使用Generate Pipeline Script
進行語法生成,如下:
生成的格式為:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
即為我們需要的用戶字符串
步驟2:編寫pipeline腳本
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 ''中執(zhí)行
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文章來源:http://www.zghlxwxcb.cn/news/detail-562304.html
參考鏈接:文章來源地址http://www.zghlxwxcb.cn/news/detail-562304.html
- https://www.saoniuhuo.com/question/detail-2324217.html
到了這里,關于Jenkins中使用pipeline進行git拉取和推送的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!