fangmd / blogsource

6 stars 0 forks source link

jenkins #71

Open fangmd opened 2 years ago

fangmd commented 2 years ago

构建参数添加 git 分支

  1. 安装插件: Active Choices
  2. 使用
image

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 2 years ago

jenkins 添加 nodejs 环境

  1. 安装插件: NodeJS
  2. /configureTools/ 下增加 nodejs
image image image
  1. 在 pipline 中使用
pipeline {
    agent { label 'mac16' }
    tools {nodejs "pnpm-node16"}

//....
fangmd commented 2 years ago

Pipeline 中使用 ssh

  1. 安装插件 SSH Agent
  2. 创建 Credentials

创建个临时view,然后在临时view中创建 Credentials

image

输入 ssh 用户名/密码,描述

image

/credentials/ 下找到 Credentials id:

image
  1. 在 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 2 years ago

pipeline archiveArtifacts

        stage('deploy') {
            steps{
                script{
                    echo "start deploy"

                        dir("${env.WORKSPACE}/xxxxxx") { 
                            archiveArtifacts artifacts: 'xxxx.tar.gz', fingerprint: true
                            //....
                        }

                }      
            }
        }