Giter Site home page Giter Site logo

jenkins_dsl_example's Introduction

DevOps, Jenkins DSL job simplified

In Short

The Jenkins DSL job is a job which will create another job(s)/pipeline(s)/etc but why create a job to create a job you may ask well, in this way your desired job will be stored as a script in a version control repository therefore you have the ability to version it and have a history of its changes, which was the motivation behind the creation of the DSL jobs in order to achieve configuration as code in Jenkins.

all you need is located in github at alicommit-malp/jenkins_dsl_example

Steps

  • install Jenkins
  • install job-dsl-plugin , how?
  • create a script in groovy language like this
  • place it in any version control repository, how?
  • create a Freestyle project in Jenkins called Seed_JOB
  • feed the created job with the location of the script in the repository
  • build the Seed_JOB, Jenkins will run your script when you build it

and your your DSL generated job(s)/pipeline(s)/etc are ready to be built.

In Detail

After the installation of the Jenkins on your system or running it in your docker daemon got the following link (supposing that you have installed Jenkins with its default port)

http://localhost:8080/newJob

Here you can create a Seed job, which is basically the job which is going to fetch the script for the actual job in a given version control repository

Jenkins new Seed job

then you need to specify the source control technology which you are using plus the link to your repository and if your repository is not public your credentials as well

DSL job source control management

afterwards, and supposing that you have installed the job-dsl-plugin

DSL plugin selection in Jenkins

you will provide the build step with relative path to the script which is going to generate your job(s)/pipeline(s)/etc

pipeline {
    agent any

    stages {
        stage('cloning repo ... ') {
            steps {
                git 'https://github.com/alicommit-malp/jenkins_dsl_example'
            }
        }
        
        stage('build'){
            agent{
                docker { 
                    image 'python:2' 
                    reuseNode true
                }    
            }
            steps{
                sh "pip install -r $WORKSPACE/python/requirements.txt"
                sh "python $WORKSPACE/python/main.py"
            }
        }
            
    }
    post{
        success{
            echo "Cool :)"
        }
    }
}

Build step Jenkins DSL job

save the job, and build it, and then if you visit the Jenkins dashboard you will see that there is a job which has been added programmatically to the list of the jobs

Jenkins dashboard show all jobs

Build the created job

There you have it, a simple tutorial to Jenkins DSL jobs. Happy coding :)

all you need is located in github at alicommit-malp/jenkins_dsl_example

jenkins_dsl_example's People

Contributors

dhang-sc avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.