Skip to content

Instantly share code, notes, and snippets.

@shaunthegeek
Last active July 9, 2020 07:59
Show Gist options
  • Select an option

  • Save shaunthegeek/7df2614b09bb89450721ccb67a9cfe2f to your computer and use it in GitHub Desktop.

Select an option

Save shaunthegeek/7df2614b09bb89450721ccb67a9cfe2f to your computer and use it in GitHub Desktop.
Jenkins git diff files when merge request
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