Created
September 14, 2021 14:41
-
-
Save nobel6018/ce7cbcd424e3805bc713f736735af0ac to your computer and use it in GitHub Desktop.
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
pipeline { | |
agent any | |
stages { | |
stage('GitClone') { | |
steps { | |
git url: 'https://github.com/nobel6018/pubsub-study.git' | |
} | |
} | |
// Todo: notify only once. 해당 로직 찾아서 구현하기 | |
stage('NotifyPush') { | |
steps { | |
script { | |
def shortHash = sh(script: "git --no-pager log -1 --format=%h", returnStdout: true).trim() | |
def hash = sh(script: "git --no-pager log -1 --format=%H", returnStdout: true).trim() | |
def message = sh(script: "git --no-pager log -1 --format=%s", returnStdout: true).trim() | |
def authorName = sh(script: "git --no-pager log -1 --format=%an", returnStdout: true).trim() | |
def branch = 'master' | |
slackSend( | |
channel: 'dev', | |
color: 'good', | |
tokenCredentialId: 'slack_notification', | |
username: 'github', | |
message: "*pushed to `<https://github.com/nobel6018/pubsub-study/somewhere|${branch}>` by ${authorName}*\n`<https://github.com/nobel6018/pubsub-study/somewhere/${hash}|${shortHash}>` - ${message}" | |
) | |
} | |
} | |
} | |
stage("NotifyBuildStart") { | |
steps { | |
script { | |
def user = "${currentBuild.getBuildCauses()[0].shortDescription} / ${currentBuild.getBuildCauses()[0].userId}" | |
slackSend( | |
channel: 'dev', | |
color: 'good', | |
tokenCredentialId: 'slack_notification', | |
username: 'Jenkins', | |
message: "${env.JOB_NAME} #[<${env.BUILD_URL.replace("/:", ":")}|${env.BUILD_NUMBER}>]. ${user}" | |
) | |
} | |
} | |
} | |
stage("AllowFileWritePermission") { | |
steps { | |
sshPublisher( | |
publishers: [ | |
sshPublisherDesc( | |
configName: 'alpha', | |
transfers: [ | |
sshTransfer( | |
execCommand: 'sudo sh /data/script/pointberry/script/file_permission_allow.sh', | |
execTimeout: 120000, | |
) | |
], | |
verbose: true | |
) | |
] | |
) | |
} | |
} | |
stage("BuildByGradle") { | |
steps { | |
sh "./gradlew clean build --info" | |
} | |
} | |
stage("DeployBlueGreen") { | |
steps { | |
sshPublisher( | |
publishers: [ | |
sshPublisherDesc( | |
configName: 'alpha', | |
transfers: [ | |
sshTransfer( | |
excludes: '', | |
execCommand: 'sudo sh /data/script/pointberry/script/total.sh', | |
execTimeout: 120000, | |
remoteDirectory: '/pointberry/deploy', | |
removePrefix: 'build/libs', | |
sourceFiles: 'build/libs/*.jar' | |
) | |
], | |
verbose: true | |
) | |
] | |
) | |
} | |
} | |
} | |
post { | |
success { | |
script { | |
def time = "${currentBuild.durationString.replace(' and counting', '')}" | |
slackSend( | |
channel: 'dev', | |
color: 'good', | |
tokenCredentialId: 'slack_notification', | |
username: 'Jenkins', | |
message: "${env.JOB_NAME} #[<${env.BUILD_URL.replace("/:", ":")}|${env.BUILD_NUMBER}>]. Success after ${time}" | |
) | |
} | |
} | |
failure { | |
script { | |
def time = "${currentBuild.durationString.replace(' and counting', '')}" | |
slackSend( | |
channel: 'dev', | |
color: 'danger', | |
tokenCredentialId: 'slack_notification', | |
username: 'Jenkins', | |
message: "${env.JOB_NAME} #[<${env.BUILD_URL.replace("/:", ":")}|${env.BUILD_NUMBER}>]. Failure after ${time}" | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment