Created
March 24, 2020 15:17
-
-
Save naturalett/1986b8ddf048761d50f1b24c8f914c7d to your computer and use it in GitHub Desktop.
buildGithubCheckPipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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