zoukankan      html  css  js  c++  java
  • Jenkins-pipeline的实现步骤

    jenkins实现持续集成

    • 搭建jenkins环境,安装插件
    • 建立pipeline公用类库,文件夹vars,默认的
    • 添加.groovy文件,可以由以下几个类库组成
      • dockerImageBuild 负责构建项目镜像
      • dockerImageDeploy 负责将镜像推到仓库
      • dockerServiceStart 负责启动docker服务
      • gitCheckout 负责迁出项目源码
      • servicePipeline 程序入口
    • 根据项目添加对应的.jenkinsfile文件
    • jenkins里建立文件夹,选择公用类库的仓库,起个名字
    • 在文件夹里建立新的Job,然后选择对象的jenkinsfile文件
    • 项目构建完成

    相关源代码分享

    1. gitCheckout源代码
    def call(body) {
        def config = [:]
        body.resolveStrategy = Closure.DELEGATE_FIRST
        body.delegate = config
        body()
    
        echo 'Checking out code from "' + config.repoUrl + '" with credentialsId "' + 
            config.credentialsId + '" ...'
        
        checkout([$class: 'GitSCM', branches: [[name: config.branches]], 
        doGenerateSubmoduleConfigurations: false, 
        extensions: [], 
        submoduleCfg: [], 
        userRemoteConfigs: [[credentialsId: config.credentialsId, url: config.repoUrl]]])   
    }
    
    1. servicePipeline.groovy源码
    def call(body) {
        def config = [:]
        body.resolveStrategy = Closure.DELEGATE_FIRST
        body.delegate = config
        body()
    
        pipeline {
            agent { label 'build-server' }
           
            stages {
                stage('Initialization') {
                    steps {
                        script {
                           echo "项目初始化"
                        }
                    }
                }
                stage('CI') {
                    steps{
                        script{
                            gitCheckout{
                                repoUrl = config.repoUrl
                                credentialsId = config.credentialsId
                                branches = config.branches
                                commit = config.commit
                            }
                        }
                    }
                }
                stage('Service') {
                echo "启动dockder服务"
              }
            }
        }
    }
    
    1. lind.jenkinsfile项目部署源码
    @Library("lind-library") _
    
    servicePipeline ( {
       repoUrl = "git@github.com:bfyxzls/LindDotNetCore.git"
       credentialsId = "012f0d4e-47e2-48ce-8b9e-cd399e9b3d61"
       branches = "dev"
     })
    
    

    事实上,上面的构建只是一个基础版本,当你的构建有多种语言组成时,你需要为他们分别写一个入口,如dotnet,nodejs,java,php,它们有自己的入口,然后再servicePipeline里去分别处理,前开发人员输入语言类型,然后统一进行处理。

  • 相关阅读:
    hdu 1426(DFS+坑爹的输入输出)
    hdu 1430(BFS+康托展开+映射+输出路径)
    hdu 1664(数论+同余搜索+记录路径)
    BestCoder Round #86 二,三题题解(尺取法)
    hdu 1226(同余搜索)
    poj 1426(同余搜索)
    poj 2251(同余)
    hdu 1044(bfs+dfs+剪枝)
    hdu 1455(DFS+好题+经典)
    安装centos7后不能联网
  • 原文地址:https://www.cnblogs.com/lori/p/9288620.html
Copyright © 2011-2022 走看看