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

    }
}
相关推荐
Lin_Aries_04212 小时前
CentOS 7 安装部署 KVM
linux·运维·centos
运维&陈同学2 小时前
【kafka01】消息队列与微服务之Kafka详解
运维·分布式·后端·微服务·云原生·容器·架构·kafka
菜鸟小灰灰3 小时前
搭建私有docker仓库
运维·docker·容器
Karoku0664 小时前
【docker集群应用】Docker网络与资源控制
运维·数据库·docker·容器
梦游钓鱼4 小时前
pyshark安装使用,ubuntu:20.04
linux·运维·ubuntu
战族狼魂5 小时前
CentOS 上安装各种应用的命令行总结
linux·运维·centos
学Linux的语莫5 小时前
ansible变量
linux·运维·服务器·ansible
爱吃喵的鲤鱼5 小时前
Linux——文件系统清尾、动静态库
linux·运维·服务器
最数据5 小时前
Linux或者Docker中时区查询和修改(差8小时问题)
linux·运维·服务器·docker·.net
java1234_小锋6 小时前
对于GC方面,在使用Elasticsearch时要注意什么?
大数据·elasticsearch·jenkins