-1

I'm learning how to use Jenkins and working on configuring a Jenkins file instead of the build using the Jenkins UI.

The source code management step for building from Bitbucket:

enter image description here

The build step for building a Docker container:

enter image description here

The build is of type multi configuration project:

enter image description here

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

enter image description here

I'm unsure how to configure the steps I've configured via the UI: Source Code Management & Build. How to convert the config for Docker and Bitbucket that can be used with a Jenkinsfile ?

blue-sky
  • 45,835
  • 124
  • 360
  • 647

1 Answers1

1

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.

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.

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. In the Pipeline tab, you will have option to select Pipeline script or Pipeline script from SCM. It's always better to start with the Pipeline script while you are building and modifying your workflow. Once it's stabilized, you can add it to the repository.

jordanvrtanoski
  • 3,296
  • 1
  • 9
  • 17
  • the UI steps 'Source Code Management' & 'Build' are not available if I create a new Pipeline job , 'Source Code Management' & 'Build' steps are available if I create a 'multi configuration project'. From https://stackoverflow.com/questions/51766803/jenkins-does-not-execute-steps-in-jenkinsfile/51767456 in order to use pipeline I need to use 'pipeline' type instead of 'multi configuration project' type. Should the UI steps 'Source Code Management' & 'Build' be available in a 'Pipeline' build type ? – blue-sky Apr 05 '21 at 09:41
  • Yes, you need to create a `pipeline` type of a project, I will clarify this in the answer – jordanvrtanoski Apr 05 '21 at 09:44
  • thanks, Jenkins does not allow the UI options 'Source Code Management' & 'Build' I've created using 'Source Code Management' in a pipeline? – blue-sky Apr 05 '21 at 09:47
  • Yes, you can not use the options from the UI as the freestyle/multiconfig projects, however the logic is very similar, the "General" options allows you to specify the SCM and the `Build` is replaced by the `Pipeline` – jordanvrtanoski Apr 05 '21 at 09:50