跨多个Docker映像的Jenkins管道 [英] Jenkins Pipeline Across Multiple Docker Images

查看:96
本文介绍了跨多个Docker映像的Jenkins管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Jenkins中的声明性管道,如何跨多个版本的Docker映像运行阶段.我想在python 2.7、3.5和3.6上执行以下jenkinsfile.以下是用于在Docker容器中构建和测试python项目的管道文件

Using a declarative pipeline in Jenkins, how do I run stages across multiple versions of a docker image. I want to execute the following jenkinsfile on python 2.7, 3.5, and 3.6. Below is a pipeline file for building and testing a python project in a docker container

pipeline {
  agent {
    docker {
      image 'python:2.7.14'
    }
  }

  stages {
    stage('Build') {
      steps {
        sh 'pip install pipenv'
        sh 'pipenv install --dev'
      }
    }

    stage('Test') {
      steps {
        sh 'pipenv run pytest --junitxml=TestResults.xml'
      }
    }
  }

  post {
    always {
      junit 'TestResults.xml'
    }
  }
}

要确保在python 3.5和3.6上执行相同的步骤,最少的代码量是多少?希望是,如果测试失败,则很明显测试将在哪个版本上失败.

What is minimal amount of code to make sure the same steps succeed across python 3.5 and 3.6? The hope is that if a test fails, it is evident which version(s) the test fails on.

或者我所要求的不是声明性管道(例如,脚本化管道可能是最优雅地解决此问题的管道)

Or is what I'm asking for not possible for declarative pipelines (eg. scripted pipelines may be what would most elegantly solve this problem)

作为比较, Travis CI让我们您指定运行在不同的python版本上.

推荐答案

我不得不求助于脚本化管道并结合所有阶段

I had to resort to a scripted pipeline and combine all the stages

def pythons = ["2.7.14", "3.5.4", "3.6.2"]

def steps = pythons.collectEntries {
    ["python $it": job(it)]
}

parallel steps

def job(version) {
    return {
        docker.image("python:${version}").inside {
            checkout scm
            sh 'pip install pipenv'
            sh 'pipenv install --dev'
            sh 'pipenv run pytest --junitxml=TestResults.xml'
            junit 'TestResults.xml'
        }
    }
}

生成的管道看起来像

理想情况下,我们可以将每个工作分解成几个阶段(设置,构建,测试),但是 用户界面 当前不支持此功能 ( 仍不受支持).

Ideally we'd be able to break up each job into stages (Setup, Build, Test), but the UI currently doesn't support this (still not supported).

这篇关于跨多个Docker映像的Jenkins管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆