Skip to content

Instantly share code, notes, and snippets.

@stephenhillier
Created September 30, 2019 15:47
Show Gist options
  • Save stephenhillier/4e6658299cc2954afd70edf6a5c6b5bd to your computer and use it in GitHub Desktop.
Save stephenhillier/4e6658299cc2954afd70edf6a5c6b5bd to your computer and use it in GitHub Desktop.
Jenkinsfile with github deployment
#!groovy
@Library('bcgov-library') _
import bcgov.GitHubHelper
// Notify stage status and pass to Jenkins-GitHub library
void notifyStageStatus (String name, String status) {
GitHubHelper.createCommitStatus(
this,
sh(returnStdout: true, script: 'git rev-parse HEAD'), // this is the most recent commit ID
status,
"${BUILD_URL}",
"Stage: ${name}",
"${name}"
)
}
// createDeployment gets a new deployment ID from GitHub.
// this lets us display notifications on GitHub when new environments
// are deployed (e.g. on a pull request page)
Long createDeployment (String suffix, String gitRef) {
def ghDeploymentId = new GitHubHelper().createDeployment(
this,
gitRef,
[
'environment':"${suffix}",
'task':"deploy:${gitRef}"
]
)
echo "deployment ID: ${ghDeploymentId}"
return ghDeploymentId
}
// Create deployment status for a deployment ID (call createDeployment first)
void createDeploymentStatus (Long ghDeploymentId, String status, String stageUrl) {
echo "creating deployment status (${status})"
new GitHubHelper().createDeploymentStatus(
this,
ghDeploymentId,
"${status}",
['targetUrl':"https://${stageUrl}/"]
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment