Skip to content

Instantly share code, notes, and snippets.

@naturalett
Created March 24, 2020 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naturalett/1986b8ddf048761d50f1b24c8f914c7d to your computer and use it in GitHub Desktop.
Save naturalett/1986b8ddf048761d50f1b24c8f914c7d to your computer and use it in GitHub Desktop.
buildGithubCheckPipeline
def check_runs = new com.functions.buildGithubCheckScript()
pipeline {
agent {
kubernetes {
label "GitHub-Check-Runs-${UUID.randomUUID().toString().substring(0,8)}"
defaultContainer 'jnlp'
}
}
stages {
stage('Checkout') {
steps {
script {
git (credentialsId: 'github-token',
url: "https://github.com/<organization-name>/" + repoName,
branch: "master")
}
}
}
stage("Build") {
steps {
script {
withCredentials([sshUserPrivateKey(credentialsId: '<credentialsId>', keyFileVariable: 'privateKey', passphraseVariable: '', usernameVariable: '')]) {
try {
build_command = sh(script: "mvn clean install", returnStatus: true)
check_runs.buildGithubCheck(<REPO_NAME>, <COMMIT_ID>, privateKey, 'success', "build")
} catch(Exception e) {
check_runs.buildGithubCheck(<REPO_NAME>, <COMMIT_ID>, privateKey, 'failure', "build")
echo "Exception: ${e}"
}
}
}
}
}
stage("Unit Test") {
steps {
script {
withCredentials([sshUserPrivateKey(credentialsId: '<credentialsId>', keyFileVariable: 'privateKey', passphraseVariable: '', usernameVariable: '')]) {
try {
def test = sh(script: "python unitTest.py", returnStdout: true)
check_runs.buildGithubCheck(<REPO_NAME>, <COMMIT_ID>, privateKey, 'success', "unit-test")
} catch(Exception e) {
check_runs.buildGithubCheck(<REPO_NAME>, <COMMIT_ID>, privateKey, 'failure', "unit-test")
echo "Exception: ${e}"
}
}
}
}
}
stage("Integration Test") {
steps {
script {
withCredentials([sshUserPrivateKey(credentialsId: '<credentialsId>', keyFileVariable: 'privateKey', passphraseVariable: '', usernameVariable: '')]) {
try {
def test = sh(script: "python integrationTest.py", returnStdout: true)
check_runs.buildGithubCheck(<REPO_NAME>, <COMMIT_ID>, privateKey, 'success', "integration-test")
} catch(Exception e) {
check_runs.buildGithubCheck(<REPO_NAME>, <COMMIT_ID>, privateKey, 'failure', "integration-test")
echo "Exception: ${e}"
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment