简体   繁体   English

如何在这些构建步骤中使用 Jenkinsfile?

[英]How to use a Jenkinsfile for these build steps?

I'm learning how to use Jenkins and working on configuring a Jenkins file instead of the build using the Jenkins UI.我正在学习如何使用 Jenkins 并致力于配置 Jenkins 文件,而不是使用 Jenkins UI 进行构建。

The source code management step for building from Bitbucket:从 Bitbucket 构建的源代码管理步骤:

在此处输入图像描述

The build step for building a Docker container:构建 Docker 容器的构建步骤:

在此处输入图像描述

The build is of type multi configuration project:构建类型为多配置项目:

在此处输入图像描述

Reading the Jenkins file documentation athttps://www.jenkins.io/doc/book/pipeline/jenkinsfile/index.html and creating a new build using Pipeline : Reading the Jenkins file documentation athttps://www.jenkins.io/doc/book/pipeline/jenkinsfile/index.html and creating a new build using Pipeline :

在此处输入图像描述

I'm unsure how to configure the steps I've configured via the UI: Source Code Management & Build .我不确定如何配置我通过 UI 配置的步骤: Source Code Management & Build How to convert the config for Docker and Bitbucket that can be used with a Jenkinsfile?如何转换可与 Jenkinsfile 一起使用的 Docker 和 Bitbucket 的配置?

The SCM will not be changed, regardless if you are using UI configuration or a pipeline, although in theory you can do the git clone from the steps in the pipeline, if you really insist convert the SCM steps in pure pipeline steps.无论您使用的是 UI 配置还是管道,SCM 都不会更改,尽管理论上您可以从管道中的步骤git clone ,如果您真的坚持将 SCM 步骤转换为纯管道步骤。

The pipeline will can have multiple stages, and each of the stages can have different execution environment.管道可以有多个阶段,每个阶段可以有不同的执行环境。 You can use the Docker pipeline plug-in , or you can use plain sh to issue the docker commands on the build agent.您可以使用Docker 管道插件,也可以使用普通sh在构建代理上发出 docker 命令。

Here is small sample from one of my manual build pipelines:这是我的手动构建管道之一的小样本:

pipeline {
    agent none
    stages {
        stage('Init') {
            agent { label 'docker-x86' }
            steps {
                checkout scm
                sh 'docker stop demo-001c || true'
                sh 'docker rm demo-001c || true'
            }
        }
        stage('Build Back-end') {
            agent { label 'docker-x86' }
            steps {
                sh 'docker build -t demo-001:latest ./docker'
            }
        }
        stage('Test') {
            agent {
                docker { 
                    label 'docker-x86' 
                }
            }
            steps {
                sh 'docker run --name demo-001c demo-001:latest'
                sh 'cd test && make test-back-end'
            }
        }
    }
}

You need to create a Pipeline type of a project and specify the SCM configuration in the General tab.您需要创建项目的Pipeline类型并在General选项卡中指定 SCM 配置。 In the Pipeline tab, you will have option to select Pipeline script or Pipeline script from SCM .Pipeline选项卡中,您可以选择 select Pipeline scriptPipeline script from SCM的管道脚本。 It's always better to start with the Pipeline script while you are building and modifying your workflow.在构建和修改工作流程时,最好从Pipeline script开始。 Once it's stabilized, you can add it to the repository.稳定后,您可以将其添加到存储库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM