Jenkins之pipeline

安装插件

  • Pipeline
  • Pipeline: Stage View Plugin

创建任务

配置

  • demo
  • 开始实践

  • 拉取git仓库代码



powershell 复制代码
checkout scmGit(branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'http://178.119.30.133:8929/root/mytest.git']])
  • 通过SonarQube做质量检测
powershell 复制代码
sh '/var/jenkins_home/sonar-scanner/bin/sonar-scanner -Dsonar.source=./ -Dsonar.projectname=${JOB_NAME} -Dsonar.projectKey=${JOB_NAME} -Dsonar.login=6c99d1bafedaa4bad18fd63fc9975515fbeb4eab'
  • 通过Docker制作自定义镜像
powershell 复制代码
sh 'docker build -t ${JOB_NAME}:$tag .'
  • 将自定义镜像推送到Harbor
powershell 复制代码
sh '''docker login -u $harborUser -p $harborPasswd $harborAddress
docker tag  $JOB_NAME:$tag  $harborAddress/$harborRepo/$JOB_NAME:$tag
docker push $harborAddress/$harborRepo/$JOB_NAME:$tag'''
  • 通过Publish Over SSH通知目标服务器
powershell 复制代码
sshPublisher(publishers: [sshPublisherDesc(configName: 'test', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: 'deploy.sh $harborAddress $harborRepo $JOB_NAME $tag $port ', execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
  • Jenkinsfile
powershell 复制代码
pipeline {
    agent any

    environment {

        harborUser = 'admin'
        harborPasswd = 'Harbor12345'
        harborAddress = '178.119.30.133:80'
        harborRepo = 'repo'
    }

    stages {
        stage('拉取git仓库代码') {
            steps {
                checkout scmGit(branches: [[name: '$tag']], extensions: [], userRemoteConfigs: [[url: 'http://178.119.30.133:8929/root/mytest.git']])
            }
        }

        stage('通过SonarQube做质量检测') {
            steps {
                sh '/var/jenkins_home/sonar-scanner/bin/sonar-scanner -Dsonar.source=./ -Dsonar.projectname=${JOB_NAME} -Dsonar.projectKey=${JOB_NAME} -Dsonar.login=6c99d1bafedaa4bad18fd63fc9975515fbeb4eab'
            }
        }
  
        stage('通过Docker制作自定义镜像') {
            steps {
                sh 'docker build -t ${JOB_NAME}:$tag .'
            }
        }

        stage('将自定义镜像推送到Harbor') {
            steps {
                sh '''docker login -u $harborUser -p $harborPasswd $harborAddress
                docker tag  $JOB_NAME:$tag  $harborAddress/$harborRepo/$JOB_NAME:$tag
                docker push $harborAddress/$harborRepo/$JOB_NAME:$tag'''
            }
        }

        stage('通过Publish Over SSH通知目标服务器') {
            steps {
                sshPublisher(publishers: [sshPublisherDesc(configName: 'test', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "deploy.sh $harborAddress $harborRepo $JOB_NAME $tag $port", execTimeout: 120000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
            }
        }

    }
}
相关推荐
努力学习的小廉2 小时前
深入了解linux系统—— 进程池
linux·运维·服务器
秃头菜狗3 小时前
各个主要目录的功能 / Linux 常见指令
linux·运维·服务器
jiunian_cn4 小时前
【Linux】centos软件安装
linux·运维·centos
藥瓿亭4 小时前
K8S认证|CKS题库+答案| 6. 创建 Secret
运维·ubuntu·docker·云原生·容器·kubernetes·cks
2302_809798324 小时前
【JavaWeb】Docker项目部署
java·运维·后端·青少年编程·docker·容器
嵌入式大圣4 小时前
Neko虚拟浏览器远程协作方案:Docker+内网穿透技术部署实践
运维·docker·容器
dmy5 小时前
n8n内网快速部署
运维·人工智能·程序员
程序员JerrySUN5 小时前
全面理解 Linux 内核性能问题:分类、实战与调优策略
java·linux·运维·服务器·单片机
米粉03055 小时前
深入剖析Nginx:从入门到高并发架构实战
java·运维·nginx·架构
huangyuchi.6 小时前
【Linux】LInux下第一个程序:进度条
linux·运维·服务器·笔记·进度条·c/c++