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 |
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)
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 | "" |
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)"
'''
}
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
...
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
...
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
...
This plugin also includes a builder plugin, so you can wrap your freestyle projects with the same goodness as the pipeline version.
Use the plugin? Let us know to get your logo here!