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)])
            }
        }

    }
}
相关推荐
0DayHP15 分钟前
HTB:Bike[WriteUP]
运维·服务器
热爱嵌入式的小许6 小时前
Linux基础项目开发1:量产工具——显示系统
linux·运维·服务器·韦东山量产工具
Pythonliu711 小时前
茴香豆 + Qwen-7B-Chat-Int8
linux·运维·服务器
你疯了抱抱我11 小时前
【RockyLinux 9.4】安装 NVIDIA 驱动,改变分辨率,避坑版本。(CentOS 系列也能用)
linux·运维·centos
小O_好好学12 小时前
CentOS 7文件系统
linux·运维·centos
哲伦贼稳妥13 小时前
一天认识一个硬件之机房地板
运维·网络·经验分享·其他
john_hjy13 小时前
11. 异步编程
运维·服务器·javascript
x晕x13 小时前
Linux dlsym符号查找疑惑分析
linux·运维·服务器
活跃的煤矿打工人13 小时前
【星海saul随笔】Ubuntu基础知识
linux·运维·ubuntu
tangdou36909865514 小时前
两种方案手把手教你多种服务器使用tinyproxy搭建http代理
运维·后端·自动化运维