jenkins
Opened this issue · 4 comments
fangmd commented
jenkins
fangmd commented
构建参数添加 git 分支
- 安装插件:
Active Choices
- 使用
BRANCH_NAME
def gettags = ("git ls-remote -t -h https://fangmingdong0224_X2C:shanhai8888@codeup.aliyun.com/6170ccd210204867ecfd4f8e/fe/travel-admin.git").execute()
return gettags.text.readLines().collect {
it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}
这里 http git 地址,账号密码中不要使用 @ 符号,账号使用 gitlab 账号不要用邮箱地址
fangmd commented
fangmd commented
Pipeline 中使用 ssh
- 安装插件
SSH Agent
- 创建 Credentials
创建个临时view,然后在临时view中创建 Credentials
输入 ssh 用户名/密码,描述
在 /credentials/
下找到 Credentials id:
- 在 pipeline 中使用 ssh
sshagent (credentials: ["3393a9bf-ade6-4169-b9e6-0bc8f3bf1f13"]) {
sh "scp -o StrictHostKeyChecking=no travel-admin.tar.gz root@39.107.157.18:/usr/share/nginx/html"
sh "ssh -o StrictHostKeyChecking=no root@39.107.157.18 \"tar -xvf /usr/share/nginx/html/travel-admin.tar.gz -C /usr/share/nginx/html/ && rm -rf /usr/share/nginx/html/old-travel-admin && mv /usr/share/nginx/html/travel-admin /usr/share/nginx/html/old-travel-admin && mv /usr/share/nginx/html/build /usr/share/nginx/html/travel-admin && rm -rf /usr/share/nginx/html/dist\""
}
问题:FATAL: [ssh-agent] Could not find specified credentials
如果出现这个问题,可以试试使用 账号+密钥 的方式创建 credentials
fangmd commented
pipeline archiveArtifacts
stage('deploy') {
steps{
script{
echo "start deploy"
dir("${env.WORKSPACE}/xxxxxx") {
archiveArtifacts artifacts: 'xxxx.tar.gz', fingerprint: true
//....
}
}
}
}