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

    }
}
相关推荐
jerry-891 小时前
系统安全及应用
linux·运维·服务器
AiFlutter1 小时前
在AlarmLinux系统中安装KeyDB
linux·运维·服务器
小徐同学14182 小时前
BGP边界网关协议(Border Gateway Protocol)路由聚合详解
运维·服务器·网络·网络协议·信息与通信·bgp
m0_748246613 小时前
(CICD)自动化构建打包、部署(Jenkins + maven+ gitlab+tomcat)
自动化·jenkins·maven
kyle~4 小时前
Linux--权限
linux·运维·服务器
谁在夜里看海.4 小时前
【Linux-网络】初识计算机网络 & Socket套接字 & TCP/UDP协议(包含Socket编程实战)
linux·运维·服务器·网络·计算机网络
小诺大人4 小时前
Linux(Centos、Ubuntu) 系统安装jenkins服务
linux·jenkins
冷影玺4 小时前
网络系统管理Linux环境——StorageSrv之Mariadb
linux·运维·mariadb
孤寂大仙v5 小时前
【Linux】进程地址空间与虚拟地址空间
linux·运维·服务器·网络·redis
豪越大豪5 小时前
智慧消防营区一体化安全管控 2024 年度深度剖析与展望
大数据·运维