【自动化持续集成必备基础】pipeline常用功能

简介

​pipeline是一套运行在jenkins上的工作流框架,可以实现复杂流程的编排和可视化运行

pipeline支持两种语法:Declarative Pipeline(声明式流水线)和Scripted Pipeline (脚本式流水线)

本文重点介绍主流的声明式流水线

创建流水线项目

在Jenkins中如果要使用pipeline流水线的话,必须安装pipeline插件

创建一个流水线项目

pipeline结构(声明式)

基础结构

pipeline {
    agent any
    stages {
        stage("stage") {
            steps {
                echo "hello pipeline"
            }
        }
    }
}

持续集成结构(部分)

pipeline {
  agent any
  stages {
    stage('pull project code') {
      steps {
        sh 'echox pull project code'
      }
    }
 
    stage('mvn package') {
      steps {
        sh 'echo mvn package'
      }
    }
 
    stage('build and push image') {
      steps {
        sh 'echo build and push image'
      }
    }
 
    stage('deploy to k8s') {
      steps {
        sh 'echo deploy to k8s'
      }
    }
 
    stage('pull autotest code') {
      steps {
        sh 'echo pull autotest code'
      }
    }
 
    stage('run autotest') {
      steps {
        sh 'echo run autotest'
      }
    }
 
    stage('allure report') {
      steps {
        sh 'echo allure report'
      }
    } 
  }
}

pipeline结构解析:pipeline

声明式流水线根节点,也是声明式流水线的开始

pipeline {}

pipeline结构解析:agent

agent指定流水线运行在哪个环境之中,有如下选项: 

any:在任何环境中执行流水线

pipeline {
    agent any
}

none:表示没有全局的agent配置,每个stage需要指定自己的agent

pipeline {
    agent none 
    stages {
        stage('allure report'){
           agent any
         }
     }
}


node:指定在某个标签的节点上运行

pipeline {
    agent none 
    stages {
        stage('allure report'){
            agent { label 'allureReport-slave-label' }
        }	    
    }
}

Dockerfile:通过dockerfile创建镜像并运行容器,在这个容器中运行,用的不多

docker:在docker中运行


k8s:运行在某一个k8s集群中,可以实现动态slave,示例:https://www.cnblogs.com/uncleyong/p/16721826.html

pipeline结构解析:stages、stage

stages:所有阶段的集合

stage:某一个阶段,stage的名称要唯一

pipeline结构解析:steps

steps:某个阶段要运行的具体步骤,包含一个或多个步骤

示例:

pipeline {
  agent any
  stages {
    stage('pull project code') {
      steps {
        sh """
          echo "pull project code"
     
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值