commit 6d394c7da5b6fe41223a5dcfca20b97d9068c17b Author: Dan Ballard Date: Fri Jun 15 14:45:17 2018 -0700 initial import of cwtch jenkinfiles diff --git a/cwtch.node.jenkinsfile b/cwtch.node.jenkinsfile new file mode 100644 index 0000000..df228c8 --- /dev/null +++ b/cwtch.node.jenkinsfile @@ -0,0 +1,111 @@ +node { + try{ + notifyBuild('STARTED') + + // ws + dir("${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/") { + withEnv(["GOROOT=/opt/go", "GOPATH=${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}", "PATH=$PATH:/opt/go/bin"]) { + withEnv(["PATH=${GOPATH}/bin:$PATH"]) { + + stage('Checkout'){ + echo 'Checking out code from git' + + //checkout scm + //git url: 'https://github.com/jfrogdev/project-examples.git' + checkout([$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[url: 'https://git.openprivacy.ca/cwtch.im/cwtch.git']]]) + } + + stage('Fetching Dependancies'){ + echo 'Pulling Dependencies' + echo "GOPATH: $GOPATH" + echo "PATH: $PATH" + + sh 'go version' + sh 'go get -u github.com/golang/lint/golint' + + dir("${GOPATH}") { + sh 'mkdir -p src/cwtch.im' + sh 'ln -sf ${GOPATH} src/cwtch.im/cwtch' + + sh """go list ./... | grep _/var | sed -e 's/^.*${BUILD_ID}//' | awk '\$0="./src/cwtch.im/cwtch"\$0' > projectPaths""" + + sh 'cat projectPaths | xargs go get' + } + } + + stage('Code Quality'){ + + dir("${GOPATH}") { + + echo 'Vetting' + sh """cat projectPaths | xargs go vet""" + + echo 'Linting' + // -set_exit_status to cause errors + sh """cat projectPaths | xargs golint""" + } + } + + stage('Unit Tests'){ + dir("${GOPATH}") { + echo 'Unit Testing' + // -race - removed until passing + sh """cat projectPaths | grep -v testing | xargs go test -cover""" + } + } + + stage('Integration Test'){ + dir("${GOPATH}") { + echo 'Integration Testing' + // -race - removed until passing + sh """go test cwtch.im/cwtch/testing""" + } + } + } + } + } + } catch (e) { + // If there was an exception thrown, the build failed + currentBuild.result = "FAILED" + echo(e) + } finally { + // Success or failure, always send notifications + notifyBuild(currentBuild.result) + } +} + +// TODO: use for cwtch notifications +def notifyBuild(String buildStatus = 'STARTED') { + // build status of null means successful + buildStatus = buildStatus ?: 'SUCCESSFUL' + + // Default values + def colorName = 'RED' + def colorCode = '#FF0000' + def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" + def summary = """${subject} + ${env.JOB_NAME}: ${env.JOB_URL} + Build: ${env.BUILD_URL}/flowGraphTable""" + + // Override default values based on build status + if (buildStatus == 'STARTED') { + color = 'YELLOW' + colorCode = '#FFFF00' + } else if (buildStatus == 'SUCCESSFUL') { + color = 'GREEN' + colorCode = '#00FF00' + } else { + color = 'RED' + colorCode = '#FF0000' + } + + // Send notifications + //slackSend (color: colorCode, message: summary) + emailext ( + subject: "[JENKINS] ${subject}", + to: 'dan@openprivacy.ca', + body: summary, + recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider']], + from: 'dan@openprivacy.ca' + ) +} \ No newline at end of file diff --git a/cwtch.pipeline.jenkinsfile b/cwtch.pipeline.jenkinsfile new file mode 100644 index 0000000..2c4b3b3 --- /dev/null +++ b/cwtch.pipeline.jenkinsfile @@ -0,0 +1,133 @@ +pipeline { + parameters { + string( + name: 'repo', + defaultValue:"cwtch.im/cwtch", + description: "repo to build from") + } + + agent any + + environment { + GOROOT = "/opt/go" + GOPATH = "${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}" + PATH = "$PATH:/opt/go/bin:${JENKINS_HOME}/jobs/${JOB_NAME}/builds/${BUILD_ID}/bin" + } + + stages { + stage('Checkout'){ + steps { + echo 'Checking out code from git' + echo params.repo + //checkout scm + //git url: 'https://github.com/jfrogdev/project-examples.git' + dir("${GOPATH}") { + checkout([$class: 'GitSCM', branches: [[name: '*/master']], userRemoteConfigs: [[url: 'https://git.openprivacy.ca/cwtch.im/cwtch.git']]]) + } + } + } + + stage('Fetching Dependancies'){ + steps { + echo 'Pulling Dependencies' + echo "GOPATH: $GOPATH" + echo "PATH: $PATH" + + + sh 'go version' + sh 'go get -u github.com/golang/lint/golint' + + dir("${GOPATH}") { + sh 'mkdir -p src/cwtch.im' + sh 'ln -sf ${GOPATH} src/cwtch.im/cwtch' + + sh """go list ./... | grep _/var | sed -e 's/^.*${BUILD_ID}//' | awk '\$0="./src/cwtch.im/cwtch"\$0' > projectPaths""" + + sh 'cat projectPaths | xargs go get' + } + } + } + + stage('Code Quality'){ + steps { + + dir("${GOPATH}") { + + echo 'Vetting' + sh """cat projectPaths | xargs go vet""" + + echo 'Linting' + // -set_exit_status to cause errors + sh """cat projectPaths | xargs golint""" + } + } + } + + stage('Unit Tests'){ + steps { + dir("${GOPATH}") { + echo 'Unit Testing' + // -race - removed until passing + sh """cat projectPaths | grep -v testing | xargs go test -cover""" + } + } + } + + stage('Integration Test'){ + steps { + dir("${GOPATH}") { + echo 'Integration Testing' + // -race - removed until passing + sh """go test cwtch.im/cwtch/testing""" + } + } + } + + } + + post { + success { + notifyBuild("SUCCESS") + } + failure { + notifyBuild("FAILURE") + } + } +} + +// TODO: use for cwtch notifications +def notifyBuild(String buildStatus = 'STARTED') { + // build status of null means successful + buildStatus = buildStatus ?: 'SUCCESSFUL' + + // Default values + def colorName = 'RED' + def colorCode = '#FF0000' + def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'" + def summary = """${subject} + ${env.JOB_NAME}: ${env.JOB_URL} + Build: ${env.BUILD_URL}/flowGraphTable""" + + // Override default values based on build status + if (buildStatus == 'STARTED') { + color = 'YELLOW' + colorCode = '#FFFF00' + } else if (buildStatus == 'SUCCESSFUL') { + color = 'GREEN' + colorCode = '#00FF00' + } else { + color = 'RED' + colorCode = '#FF0000' + } + + // Send notifications + //slackSend (color: colorCode, message: summary) + emailext ( + subject: "[JENKINS] ${subject}", + to: 'dan@openprivacy.ca', + body: summary, + recipientProviders: [[$class: 'DevelopersRecipientProvider'], [$class: 'CulpritsRecipientProvider']], + from: 'dan@openprivacy.ca' + ) +} +