Last active
July 9, 2020 07:59
-
-
Save shaunthegeek/7df2614b09bb89450721ccb67a9cfe2f to your computer and use it in GitHub Desktop.
Jenkins git diff files when merge request
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 | |
| stages { | |
| stage('checkout') { | |
| steps { | |
| checkout([ | |
| $class: 'GitSCM', | |
| branches: [[name: '*']], | |
| userRemoteConfigs: [[url: env.GIT_REPO_URL, credentialsId: env.CREDENTIALS_ID]] | |
| ]) | |
| script { | |
| if ( env.MR_SOURCE_BRANCH ==~ /.*/ ) { | |
| sh "git checkout ${env.MR_TARGET_BRANCH}" | |
| sh "git checkout ${env.MR_SOURCE_BRANCH}" | |
| } else { | |
| sh "git checkout ${env.GIT_COMMIT}" | |
| } | |
| } | |
| } | |
| } | |
| stage('install') { | |
| steps { | |
| sh 'npm install' | |
| } | |
| } | |
| stage('lint') { | |
| when { | |
| expression { env.MR_SOURCE_BRANCH ==~ /.*/ } | |
| } | |
| steps { | |
| sh "git diff --diff-filter=d --name-only ${env.MR_TARGET_BRANCH}... | grep '.md\$' | xargs npx remark -f" | |
| } | |
| } | |
| stage('build') { | |
| steps { | |
| sh 'npx hexo generate' | |
| } | |
| } | |
| stage('deploy') { | |
| when { | |
| anyOf { | |
| branch 'master' | |
| tag '*' | |
| } | |
| } | |
| steps { | |
| sh 'npx hexo deploy' | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment