diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..44b8a1f --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,91 @@ +node { + notify1('Started testing-whaleapp build') + try { + stage('Checkout') { + checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[url: 'https://github.com/chilu49/hellowhale.git']]]) + } + stage('Build Image And Push') { + dir('/opt/jenkins/workspace/testing-asdfkljasdf/'){ + def app = docker.build ("testing-whaleapp:${env.BUILD_ID}") + } + } + + stage ('Deploy-dev') { + //build job: 'account-service-pipeline', wait: false + sh ''' docker stop testing-whaleapp''' + sh ''' docker rm testing-whaleapp ''' + sh ''' docker run -d -it --name testing-whaleapp testing-whaleapp:${BUILD_NUMBER}''' + + } + notify2('Successfully Deployed testing-whaleapp') + } catch (err) { + notify1("Error {err}") + currentBuild.result = 'FAILURE' + } +} +@NonCPS +def getChangeLog(passedBuilds) { + def changeString = "" + for (int x = 0; x < passedBuilds.size(); x++) { + def currentBuild = passedBuilds[x]; + def changeLogSets = currentBuild.changeSets + for (int i = 0; i < changeLogSets.size(); i++) { + def entries = changeLogSets[i].items + for (int j = 0; j < entries.length; j++) { + def entry = entries[j] + changeString += "* ${entry.msg} by ${entry.author} \n" + } + } + } +if (!changeString) { +changeString = " - No new changes" + } + return log; +} + +@NonCPS +def getChangeString() { + MAX_MSG_LEN = 1000 + def changeString = "" + echo "Gathering SCM changes" + def changeLogSets = currentBuild.changeSets + echo "${changeLogSets}" + echo "${changeLogSets.size()}" + for (int i = 0; i < changeLogSets.size(); i++) { + def entries = changeLogSets[i].items + for (int j = 0; j < entries.length; j++) { + def entry = entries[j] + truncated_msg = entry.msg.take(MAX_MSG_LEN) + changeString += " - ${truncated_msg} [${entry.author}]\n" + } + } + + if (!changeString) { + changeString = " - No new changes" + } + return changeString + } + + def notify1(status){ + emailext( + to: "ravinder.chiluveru@cabelas.com", + subject: "${status}:' [${env.BUILD_NUMBER}]'", + body: """

${status}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':

+

Check console output at ${env.JOB_NAME} [${env.BUILD_NUMBER}]

""" + ) + } + def notify2(status){ + emailext( + to: "ravinder.chiluveru@cabelas.com", + subject: "${status}: Job ${env.JOB_NAME} [${env.BUILD_NUMBER}]", + body: "Changes:\n " + getChangeString() + "\n\n
Check console output at: $BUILD_URL/console" + "\n" + ) + } + def notify3(status){ + emailext( + to: "ravinder.chiluveru@cabelas.com", + subject: "${status}:' [${env.BUILD_NUMBER}]'", + body: "Changes:\n " + getChangeString() + "\n\n
Check console output at: $BUILD_URL/console" + "\n" + ) + } +