-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update commit status outside pull request #79
Comments
This would fit in great with the idea of representing the entire |
Is someone working on this ? This would be a pretty handy feature. Currently, the options to interact with Github's APIs are kind of limited in the sense that we'd need install multiple plugins. |
We handle this with a shared pipeline method to use the Github plugin like following: /* groovylint-disable CouldBeSwitchStatement, DuplicateStringLiteral */
// https://plugins.jenkins.io/github/#plugin-content-setting-commit-status
void call(Map config = [:]) {
if (!(config.containsKey('context') && config.containsKey('state'))) {
error "Error - unexpected state encountered when setting git status (expecting context/state): $config"
}
String state = config.state.toUpperCase()
List allowedStates = ['PENDING', 'SUCCESS', 'ERROR', 'FAILURE']
if (!allowedStates.contains(state)) {
error "Error - unexpected commit state encountered when setting git status (expecting one of $allowedStates): $state"
}
String message = null
if (config.containsKey('message')) {
message = config.message
} else if (state == 'SUCCESS') {
message = 'This commit looks good'
} else if (state == 'ERROR') {
message = 'This commit encountered an error'
} else if (state == 'FAILURE') {
message = 'This commit failed'
} else {
message = 'This commit is being built'
}
String repoUrl = config.containsKey('repoUrl') ? config.repoUrl : env.GIT_URL
String commit = config.containsKey('commit') ? config.commit : env.GIT_COMMIT
step([
$class: 'GitHubCommitStatusSetter',
reposSource: [$class: 'ManuallyEnteredRepositorySource', url: repoUrl],
commitShaSource: [$class: 'ManuallyEnteredShaSource', sha: commit],
contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: config.context],
errorHandlers: [[$class: 'ShallowAnyErrorHandler']],
statusResultSource: [
$class: 'ConditionalStatusResultSource',
results: [
[$class: 'AnyBuildResult', state: state, message: message],
]
]
])
} Usage is like following from within a pipeline file: setGitStatus(context: 'my-status-name', state: 'pending')
setGitStatus(context: 'my-status-name', state: 'success') Hope it helps! |
Does anyone know if there's a way to update a commit status when not building a pull request?
Our deployment infrastructure uses the commit status on master to determine whether it's safe to deploy. We're using https://github.com/jenkinsci/pipeline-githubnotify-step-plugin to do that right now but it would be nice to only use one plugin :)
The text was updated successfully, but these errors were encountered: