Skip to content

liam-verta/jenkins-pipeline-goodness

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jenkins-pipeline-goodness Build Status

Daily usage Jenkins Pipeline utilities covered by JUnit tests.

Basic usage

In your Jenkninsfile

#!groovy

node {
    def docker
    String version

    stage("checkout code") {
        // checkout your code here or there ...

        // and then:
        checkout([$class                           : 'GitSCM',
                  extensions                       : [[$class           : 'RelativeTargetDirectory',
                                                       relativeTargetDir: 'jenkins-pipeline-goodness'],
                                                      [$class           : 'CleanCheckout']],
                  userRemoteConfigs                : [[url: '[email protected]:doublescoring/jenkins-pipeline-goodness.git']], // Jenkins Pipeline Goodness url
                  branches                         : [[name: 'refs/tags/1.1.1']]]) // Jenkins Pipeline Goodness version
    }
    docker = load "jenkins-pipeline-goodness/src/main/groovy/docker.groovy" // attach docker module
    try {
        stage("build image") {
            dir('path/to/your/dockerfile/') {
                def dockerFileContent = readFile('Dockerfile')
                version = docker.readVersion(dockerFileContent)
                echo "Found version in Dockerfile ${version}"
                docker.imageBuildPush("organization/name", version, "latest", "our-private-registry:12345")
            }
        }
    } finally {
        if (something_exists_that_we_must_clean) {
            docker.stopById(dockerContainerId);
            docker.removeImage("organization/name", version);
        }
    }
}

Utilities

  • exec - Execute command inside docker image
  • imageBuildPush - Build a docker image, tag it, and push to repo
  • run - Run a docker image, wait the TCP port to be ready, return container Id
  • removeImage - Remove image from repo
  • stopById - Stop docker container.
  • readVersion - Read LABEL version="n.n.n" from Dockerfile
  • temporaryFile - Get temporary file

Simple airflow integration. Support for DAG triggering passing config from Jenkins.

  • trigger - Trigger DAG
  • getState - Return DAG state (running/failed/...)
  • waitFor - Wait for DAG finish, i.e. success or failed state

Important: getState and waitFor require Airflow version 1.10.3 or higher

Tests

mvn test - for all tests

mvn -Dtest=environmentTest test - for environment tests

Versioning Guidelines

This project follow Apache rules of semantic versioning. Use git tags of the current project.

CONTRIBUTORS

  • Alexey Aksenov
  • Pavel Shuvalov

LICENSE

The Jenkins Pipeline Goodness Project is licensed to you under the terms of the Apache License, version 2.0, a copy of which has been included in the LICENSE file. Please check the individual source files for details.

Copyright

Copyright © 2016-2020 DoubleData Ltd. All rights reserved.

Apache License

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Groovy 99.9%
  • Dockerfile 0.1%