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

    }
}
相关推荐
Ztiddler4 小时前
【Linux Shell命令-不定期更新】
linux·运维·服务器·ssh
小小不董4 小时前
Oracle OCP认证考试考点详解082系列16
linux·运维·服务器·数据库·oracle·dba
IPdodo全球网络4 小时前
如何利用静态住宅IP优化Facebook商城的网络稳定性与运营效率
运维·服务器
运维&陈同学5 小时前
【模块一】kubernetes容器编排进阶实战之k8s基础概念
运维·docker·云原生·容器·kubernetes·云计算
m0_519523106 小时前
Linux——简单认识vim、gcc以及make/Makefile
linux·运维·vim
mit6.8246 小时前
[Docker#4] 镜像仓库 | 部分常用命令
linux·运维·docker·容器·架构
zyp2468106 小时前
Linux之DNS服务器
linux·运维·服务器
wdxylb6 小时前
将C++搭建的简单HTTP服务器升级为 HTTPS 服务器
运维·服务器·https
Denzel张7 小时前
ubuntu_dpkg_dep_list
linux·运维·ubuntu
dessler7 小时前
云计算&虚拟化-虚拟化技术介绍
linux·运维·云计算