Created
September 21, 2019 18:39
-
-
Save strund3r/7baa1e3d28ba62517650bce22a2de618 to your computer and use it in GitHub Desktop.
Jenkins
This file contains hidden or 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
| pipeline { | |
| agent any | |
| options { | |
| timestamps() | |
| gitLabConnection('GitLab') | |
| gitlabBuilds(builds: ['JUnit Test', 'SonarQube Analysis', 'Quality Gate']) | |
| } | |
| environment { | |
| pipeline = "${env.JOB_NAME}" | |
| } | |
| triggers { | |
| gitlab(triggerOnPush: true, | |
| triggerOnMergeRequest: false, | |
| ciSkip: false, | |
| branchFilterType: 'All', | |
| pendingBuildName: 'Pending Build') | |
| } | |
| stages { | |
| stage('Iniciando Pipeline') { | |
| when { | |
| branch 'master' | |
| } | |
| steps { | |
| //curl -s -X POST https://api.telegram.org/bot[TOKENID]/sendMessage -d chat_id=[ID] -d text="your message" | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='⏳ Iniciando Pipeline ${pipeline}'" | |
| } | |
| } | |
| stage('JUnit Test'){ | |
| agent { | |
| docker { | |
| image 'python:3.7' | |
| } | |
| } | |
| steps { | |
| sh "echo 'abc'" | |
| withEnv(["HOME=${env.WORKSPACE}"]) { | |
| sh 'pip install --user -r requirements.txt' | |
| sh 'pytest --verbose --junitxml=test-reports/results.xml tests.py' | |
| } | |
| } | |
| post { | |
| always { | |
| junit 'test-reports/*.xml' | |
| } | |
| success { | |
| updateGitlabCommitStatus name: 'JUnit Test', state: 'success' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='✅ Etapa JUnit Test concluída com sucesso!'" | |
| } | |
| failure { | |
| updateGitlabCommitStatus name: 'JUnit Test', state: 'failed' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='Etapa JUnit Test terminada com falha! Pipeline finalizado por erro!'" | |
| } | |
| } | |
| } | |
| stage('SonarQube Analysis') { | |
| steps { | |
| script { | |
| def scannerHome = tool 'SonarQube Scanner'; | |
| withSonarQubeEnv('SonarQube') { | |
| // -Dsonar.branch.name=$BRANCH_NAME | |
| sh "${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=teste-jenkins -Dsonar.sources=. -Dsonar.host.url=https://sonar.supera.com.br -Dsonar.login=XXXXXXXXXXXXXXXXXX" | |
| } | |
| } | |
| } | |
| post { | |
| success { | |
| updateGitlabCommitStatus name: 'SonarQube Analysis', state: 'success' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='✅ Etapa `SonarQube Analysis´ concluída com sucesso!'" | |
| } | |
| failure { | |
| updateGitlabCommitStatus name: 'SonarQube Analysis', state: 'failed' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='Etapa `SonarQube Analysis´ terminada com falha! Pipeline finalizado por erro!'" | |
| } | |
| } | |
| } | |
| stage('Quality Gate') { | |
| steps { | |
| waitForQualityGate abortPipeline: true | |
| } | |
| post { | |
| success { | |
| updateGitlabCommitStatus name: 'Quality Gate', state: 'success' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='✅Etapa `Quality Gate´ concluída com sucesso!'" | |
| } | |
| failure { | |
| updateGitlabCommitStatus name: 'Quality Gate', state: 'failed' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='Etapa `Quality Gate´ terminada com falha! Pipeline finalizado por erro!'" | |
| } | |
| } | |
| } | |
| stage('Build Image') { | |
| when { | |
| branch 'master' | |
| } | |
| steps { | |
| script { | |
| app = docker.build("strund3r/catweb-docker") | |
| } | |
| } | |
| post { | |
| success { | |
| updateGitlabCommitStatus name: 'Build Image', state: 'success' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='✅ Etapa `Build Image´ concluída com sucesso!'" | |
| } | |
| failure { | |
| updateGitlabCommitStatus name: 'Build Image', state: 'failed' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='Etapa `Build Image´ terminada com falha! Pipeline finalizado por erro!'" | |
| } | |
| } | |
| } | |
| stage('Push Image') { | |
| when { | |
| branch 'master' | |
| } | |
| steps { | |
| //sh "echo 'abc'" | |
| script { | |
| withDockerRegistry(credentialsId: 'LoginDocker', url: 'https://registry.supera.com.br') { | |
| app.push("${env.BUILD_NUMBER}") | |
| app.push("latest") | |
| } | |
| } | |
| } | |
| post { | |
| success { | |
| updateGitlabCommitStatus name: 'Push Image', state: 'success' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='Etapa `Push Image´ concluída com sucesso!'" | |
| } | |
| failure { | |
| updateGitlabCommitStatus name: 'Push Image', state: 'failed' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='Etapa `Push Image´ terminada com falha! Pipeline finalizado por erro!'" | |
| } | |
| } | |
| } | |
| stage('Deploy via SSH'){ | |
| when { | |
| branch 'master' | |
| } | |
| steps{ | |
| //sh "scp deploy.sh [email protected]:/home/jenkins" | |
| sh 'ssh -tt -o StrictHostKeyChecking=no [email protected] "cd /supera/teste-jenkins/ && sudo git pull origin master"' | |
| // sh "ssh -tt -o StrictHostKeyChecking=no [email protected] sudo chmod +x /supera/teste-jenkins/deploy.sh" | |
| // sh "ssh -tt -o StrictHostKeyChecking=no [email protected] /supera/teste-jenkins/deploy.sh" | |
| // sh "ssh -tt -o StrictHostKeyChecking=no [email protected] sudo chmod -x /supera/teste-jenkins/deploy.sh" | |
| //sh "ssh -o StrictHostKeyChecking=no [email protected] rm -r /home/jenkins/deploy.sh" | |
| } | |
| post{ | |
| success { | |
| updateGitlabCommitStatus name: 'Deploy via SSH', state: 'success' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='Etapa `Deploy via SSH´ concluída com sucesso!'" | |
| } | |
| failure { | |
| updateGitlabCommitStatus name: 'Deploy via SSH', state: 'failed' | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='❌ Etapa `Deploy via SSH´ terminada com falha! Pipeline finalizado por erro!'" | |
| } | |
| } | |
| } | |
| stage('Pipeline Finalizado') { | |
| steps { | |
| //curl -s -X POST https://api.telegram.org/bot[TOKENID]/sendMessage -d chat_id=[ID] -d text="your message" | |
| sh "curl -s -X POST https://api.telegram.org/botXXXXXXXX:XXXXXXXXXXXXXXX/sendMessage -d chat_id=XXXXXXXXXX -d text='🎉 Pipeline Finalizado! Projeto atualizado com sucesso!'" | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or 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
| ace-editor | |
| ant | |
| antisamy-markup-formatter | |
| apache-httpcomponents-client-4-api | |
| authentication-tokens | |
| blueocean | |
| blueocean-autofavorite | |
| blueocean-bitbucket-pipeline | |
| blueocean-commons | |
| blueocean-config | |
| blueocean-core-js | |
| blueocean-dashboard | |
| blueocean-display-url | |
| blueocean-events | |
| blueocean-git-pipeline | |
| blueocean-github-pipeline | |
| blueocean-i18n | |
| blueocean-jira | |
| blueocean-jwt | |
| blueocean-personalization | |
| blueocean-pipeline-api-impl | |
| blueocean-pipeline-editor | |
| blueocean-pipeline-scm-api | |
| blueocean-rest | |
| blueocean-rest-impl | |
| blueocean-web | |
| bouncycastle-api | |
| branch-api | |
| build-timeout | |
| cloudbees-bitbucket-branch-source | |
| cloudbees-folder | |
| command-launcher | |
| credentials | |
| credentials-binding | |
| dashboard-view | |
| display-url-api | |
| docker-commons | |
| docker-workflow | |
| durable-task | |
| email-ext | |
| embeddable-build-status | |
| external-monitor-job | |
| favorite | |
| git | |
| git-client | |
| git-server | |
| github | |
| github-api | |
| github-branch-source | |
| gitlab-logo | |
| gitlab-plugin | |
| gradle | |
| handlebars | |
| handy-uri-templates-2-api | |
| htmlpublisher | |
| jackson2-api | |
| jdk-tool | |
| jenkins-design-language | |
| jira | |
| jquery-detached | |
| jsch | |
| junit | |
| ldap | |
| lockable-resources | |
| mailer | |
| mapdb-api | |
| matrix-auth | |
| matrix-project | |
| mercurial | |
| modernstatus | |
| momentjs | |
| pam-auth | |
| pipeline-build-step | |
| pipeline-github-lib | |
| pipeline-graph-analysis | |
| pipeline-input-step | |
| pipeline-milestone-step | |
| pipeline-model-api | |
| pipeline-model-declarative-agent | |
| pipeline-model-definition | |
| pipeline-model-extensions | |
| pipeline-rest-api | |
| pipeline-stage-step | |
| pipeline-stage-tags-metadata | |
| pipeline-stage-view | |
| plain-credentials | |
| pubsub-light | |
| resource-disposer | |
| ruby-runtime | |
| scm-api | |
| script-security | |
| sonar | |
| sse-gateway | |
| ssh-credentials | |
| ssh-slaves | |
| structs | |
| subversion | |
| timestamper | |
| token-macro | |
| variant | |
| view-job-filters | |
| windows-slaves | |
| workflow-aggregator | |
| workflow-api | |
| workflow-basic-steps | |
| workflow-cps | |
| workflow-cps-global-lib | |
| workflow-durable-task-step | |
| workflow-job | |
| workflow-multibranch | |
| workflow-scm-step | |
| workflow-step-api | |
| workflow-support | |
| ws-cleanup |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment