Code Monkey home page Code Monkey logo

pipeline-gitstatuswrapper-plugin's Introduction

Pipeline Git Status Wrapper Plugin

Build Status

This plugin lets you wrap a block of commands with gitStatusWrapper, which handles updating GitHub statuses automatically!

โœ… gitStatusWrapper makes your life easier! โœ…

stage('EZPZ Updates') {
    steps {
        gitStatusWrapper(credentialsId: 'github-token', gitHubContext: 'Status', description: 'Validating') {
            sh "./do_stuff.sh"
        }
    }
}

๐Ÿ’€๐Ÿšซ Stop calling githubNotify 3+ times ๐Ÿšซ๐Ÿ’€

stage('Annoying status updates') {
    script {
      try {
        githubNotify(credentialsId: 'github-token', context: 'Status', description: 'Validating', status: 'PENDING')
        sh "./do_stuff.sh"
        githubNotify(credentialsId: 'github-token', context: 'Status', description: 'Validating', status: 'SUCCESS')
      }
      catch (Exception e) {
        githubNotify(credentialsId: 'github-token', gitHubContext: 'Status', description: 'Validating', status: 'FAILURE')
      }
    }
}

The available parameters are:

Parameter Description
credentialsId The id of the github's credentials to use, must be of type UsernameAndPassword and contain the password or a personal access token.
description A short description for the status
gitHubContext The status context. GitHub uses the context to differentiate statuses
sha The sha that identifies the commit to set the status on
repo The repo that owns the commit we want to set the status on
account The account that owns the repository
gitApiUrl GitHub Enterprise instance API URL
targetUrl The targetUrl for the notification
successDescription A short description for the status if wrapped steps succeed Can be Regex
failureDescription A short description for the status if wrapped steps fail. Can be Regex

Inferring parameter values and defaults

Inferring

Instead of specify all your parameters, this step will try to infer some of them if they are not provided. The parameters that can be inferred are:

Parameter
credentialsId
sha
repo
account

Note that infer will only work if you have Git Build Data. If you find problems when inferring, specify the required data explicitly. (You can access this data on your Jenkinsfile by using the appropriate env variables)

Defaults

The plugin will default some parameters as a convenience. The following are defaults:

Parameter Default
gitApiUrl https://api.github.com
gitHubContext "gitStatusWrapper"
targetUrl The jenkins project build URL
description ""

Regex descriptions

Since 1.1.0

You can now specify a regex pattern for the successDescription and failureDescription parameters. This regex will be used to match against the entire build log. It will use the first group match as the description for the respective status message.

To enable, wrap your regex with '/' to have it evaluted as regex.

Example:

gitStatusWrapper(credentialsId: 'github-token', description: 'Pending description', gitHubContext: 'jenkins/appTests', 
                successDescription='/^buildVersion=(.*)$/') {
   sh '''
   echo "buildVersion=$(./my_script.sh)"
   '''
}

Examples

Explicit settings

Jenkinsfile:

pipeline {
    agent any
    stages {
        stage('Run tests') {
            steps {
                gitStatusWrapper(credentialsId: 'github-token', description: 'Running Tests', gitHubContext: 'jenkins/appTests', 
                sha: 'ffg2ab', repo: 'my-repo', account: 'myaccount', gitApiUrl: 'https://[github.mycorp.com]/api/', 
                targetUrl: 'https://[myTestingSite].me') {
                    sh "./get_test_data.sh"
                    sh "./run_my_tests.sh"
                }
            }
        }
    }
}

Output:

...
[Pipeline] gitStatusWrapper
[GitStatusWrapper] - Setting PENDING status for jenkins/appTests on commit ffg2ab130985981ac0735f9789e19750f7200bd6
[Pipeline] {
[Pipeline] sh
+ ./get_test_data.sh
success
[Pipeline] sh
+ ./run_my_tests.sh
ok
ok
ok
[Pipeline] }
[GitStatusWrapper] - Setting SUCCESS status for jenkins/appTests on commit ffg2ab130985981ac0735f9789e19750f7200bd6
...

Inferring properties and default values

Pipeline job with Jenkinsfile from SCM

pipeline {
    agent any
    stages {
        stage('Run tests') {
            steps {
                gitStatusWrapper(credentialsId: 'github-token') {
                    sh "./get_test_data.sh"
                    sh "./run_my_tests.sh"
                }
            }
        }
    }
}

Output:

...
[Pipeline] gitStatusWrapper
[GitStatusWrapper] - Setting PENDING status for gitStatusWrapper on commit ffg2ab130985981ac0735f9789e19750f7200bd6
[Pipeline] {
[Pipeline] sh
+ ./get_test_data.sh
success
[Pipeline] sh
+ ./run_my_tests.sh
ok
ok
ok
[Pipeline] }
[GitStatusWrapper] - Setting SUCCESS status for gitStatusWrapper on commit ffg2ab130985981ac0735f9789e19750f7200bd6
...

Example of failure

Pipeline job with Jenkinsfile from SCM

pipeline {
    agent any
    stages {
        stage('Run tests') {
            steps {
                gitStatusWrapper(credentialsId: 'github-token') {
                    sh "./get_test_data.sh"
                    sh "./run_my_tests.sh"
                }
            }
        }
    }
}

Output:

...
[Pipeline] gitStatusWrapper
[GitStatusWrapper] - Setting PENDING status for gitStatusWrapper on commit ffg2ab130985981ac0735f9789e19750f7200bd6
[Pipeline] {
[Pipeline] sh
+ ./get_test_data.sh
success
[Pipeline] sh
+ ./run_my_tests.sh
ok
ok
! failure com.project.TestCalcs.java !
[Pipeline] }
[GitStatusWrapper] - Setting Failure status for gitStatusWrapper on commit ffg2ab130985981ac0735f9789e19750f7200bd6
...

No pipeline? No Problem

This plugin also includes a builder plugin, so you can wrap your freestyle projects with the same goodness as the pipeline version.

Users

Use the plugin? Let us know to get your logo here!

---------Created and Used by---------

---------------------------------------

pipeline-gitstatuswrapper-plugin's People

Contributors

bozaro avatar hello-woof avatar oleg-nenashev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.