2018-06-11 20:53:37 +00:00
|
|
|
pipeline {
|
2018-06-13 19:57:04 +00:00
|
|
|
agent { label 'pr-lint-slave' }
|
2018-07-17 18:21:19 +00:00
|
|
|
options {
|
2018-07-17 18:26:37 +00:00
|
|
|
timestamps()
|
|
|
|
ansiColor('xterm')
|
2018-11-22 09:15:08 +00:00
|
|
|
timeout(time: 3, unit: 'HOURS')
|
2018-07-17 18:21:19 +00:00
|
|
|
}
|
2018-06-11 20:53:37 +00:00
|
|
|
environment {
|
|
|
|
PYENV_ROOT = "/usr/local/pyenv"
|
|
|
|
PATH = "$PYENV_ROOT/bin:$PATH"
|
2018-07-17 19:57:00 +00:00
|
|
|
PY_COLORS = 1
|
2018-06-11 20:53:37 +00:00
|
|
|
}
|
|
|
|
stages {
|
2018-06-19 22:55:05 +00:00
|
|
|
stage('github-pending') {
|
|
|
|
steps {
|
|
|
|
githubNotify credentialsId: 'test-jenkins-credentials',
|
2018-11-29 12:44:11 +00:00
|
|
|
description: 'Python lint on changes begins...',
|
2018-06-19 22:55:05 +00:00
|
|
|
status: 'PENDING',
|
|
|
|
context: "jenkins/pr/lint"
|
|
|
|
}
|
|
|
|
}
|
2018-06-13 19:57:04 +00:00
|
|
|
stage('setup') {
|
2018-06-11 20:53:37 +00:00
|
|
|
steps {
|
2018-08-10 23:27:58 +00:00
|
|
|
sh '''
|
2018-10-20 14:30:54 +00:00
|
|
|
# Need -M to detect renames otherwise they are reported as Delete and Add, need -C to detect copies, -C includes -M
|
|
|
|
# -M is on by default in git 2.9+
|
2018-11-22 09:15:08 +00:00
|
|
|
git diff --name-status -l99999 -C "origin/$CHANGE_TARGET" > file-list-status.log
|
2018-10-21 09:06:41 +00:00
|
|
|
# the -l increase the search limit, lets use awk so we do not need to repeat the search above.
|
|
|
|
gawk 'BEGIN {FS="\\t"} {if ($1 != "D") {print $NF}}' file-list-status.log > file-list-changed.log
|
|
|
|
gawk 'BEGIN {FS="\\t"} {if ($1 == "D") {print $NF}}' file-list-status.log > file-list-deleted.log
|
2018-11-22 09:15:08 +00:00
|
|
|
(git diff --name-status -l99999 -C "origin/$CHANGE_TARGET" "origin/$BRANCH_NAME";echo "---";git diff --name-status -l99999 -C "origin/$BRANCH_NAME";printenv|grep -E '=[0-9a-z]{40,}+$|COMMIT=|BRANCH') > file-list-experiment.log
|
|
|
|
echo 254 > pylint-salt-chg.exit # assume failure
|
2018-11-29 12:44:11 +00:00
|
|
|
echo 254 > pylint-salt-full.exit # assume failure
|
2018-11-22 09:15:08 +00:00
|
|
|
echo 254 > pylint-tests-chg.exit # assume failure
|
2018-11-29 12:44:11 +00:00
|
|
|
echo 254 > pylint-tests-full.exit # assume failure
|
2018-08-10 23:27:58 +00:00
|
|
|
eval "$(pyenv init -)"
|
|
|
|
pyenv --version
|
|
|
|
pyenv install --skip-existing 2.7.14
|
|
|
|
pyenv local 2.7.14
|
|
|
|
pyenv shell 2.7.14
|
|
|
|
python --version
|
|
|
|
pip install tox
|
|
|
|
'''
|
2018-10-24 12:39:27 +00:00
|
|
|
archiveArtifacts artifacts: 'file-list-status.log,file-list-changed.log,file-list-deleted.log,file-list-experiment.log'
|
2018-06-11 20:53:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-22 09:15:08 +00:00
|
|
|
stage('linting chg') {
|
2018-06-11 22:57:55 +00:00
|
|
|
parallel {
|
2018-11-29 12:44:11 +00:00
|
|
|
stage('lint salt chg') {
|
2018-10-20 14:30:54 +00:00
|
|
|
when {
|
|
|
|
expression { return readFile('file-list-changed.log') =~ /(?i)(^|\n)(salt\/.*\.py|setup\.py)\n/ }
|
|
|
|
}
|
2018-06-11 22:57:55 +00:00
|
|
|
steps {
|
2018-08-10 23:27:58 +00:00
|
|
|
sh '''
|
|
|
|
eval "$(pyenv init - --no-rehash)"
|
2018-11-22 09:15:08 +00:00
|
|
|
# tee makes the exit/return code always 0
|
2018-11-29 12:44:11 +00:00
|
|
|
grep -Ei '^salt/.*\\.py$|^setup\\.py$' file-list-changed.log | (xargs -r '--delimiter=\\n' tox -e pylint-salt ; echo "$?" > pylint-salt-chg.exit) | tee pylint-report-salt-chg.log
|
2018-10-20 14:30:54 +00:00
|
|
|
# remove color escape coding
|
2018-11-29 12:44:11 +00:00
|
|
|
sed -ri 's/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' pylint-report-salt-chg.log
|
2018-11-22 09:15:08 +00:00
|
|
|
read rc_exit < pylint-salt-chg.exit
|
|
|
|
exit "$rc_exit"
|
2018-08-10 23:27:58 +00:00
|
|
|
'''
|
2018-06-11 22:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-29 12:44:11 +00:00
|
|
|
stage('lint test chg') {
|
2018-10-20 14:30:54 +00:00
|
|
|
when {
|
|
|
|
expression { return readFile('file-list-changed.log') =~ /(?i)(^|\n)tests\/.*\.py\n/ }
|
|
|
|
}
|
2018-06-11 22:57:55 +00:00
|
|
|
steps {
|
2018-08-10 23:27:58 +00:00
|
|
|
sh '''
|
|
|
|
eval "$(pyenv init - --no-rehash)"
|
2018-11-22 09:15:08 +00:00
|
|
|
# tee makes the exit/return code always 0
|
2018-11-29 12:44:11 +00:00
|
|
|
grep -Ei '^tests/.*\\.py$' file-list-changed.log | (xargs -r '--delimiter=\\n' tox -e pylint-tests ; echo "$?" > pylint-tests-chg.exit) | tee pylint-report-tests-chg.log
|
2018-10-20 14:30:54 +00:00
|
|
|
# remove color escape coding
|
2018-11-29 12:44:11 +00:00
|
|
|
sed -ri 's/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' pylint-report-tests-chg.log
|
2018-11-22 09:15:08 +00:00
|
|
|
read rc_exit < pylint-tests-chg.exit
|
|
|
|
exit "$rc_exit"
|
2018-08-10 23:27:58 +00:00
|
|
|
'''
|
2018-06-11 22:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-11 20:53:37 +00:00
|
|
|
}
|
2018-11-22 09:15:08 +00:00
|
|
|
post {
|
|
|
|
always {
|
2018-11-30 12:36:07 +00:00
|
|
|
archiveArtifacts artifacts: 'pylint-report-*-chg.log', allowEmptyArchive: true
|
2018-11-22 09:15:08 +00:00
|
|
|
step([$class: 'WarningsPublisher',
|
|
|
|
parserConfigurations: [[
|
|
|
|
parserName: 'PyLint',
|
2018-11-30 12:36:07 +00:00
|
|
|
pattern: 'pylint-report-*-chg.log'
|
2018-11-22 09:15:08 +00:00
|
|
|
]],
|
|
|
|
failedTotalAll: '0',
|
|
|
|
useDeltaValues: false,
|
|
|
|
canRunOnFailed: true,
|
|
|
|
usePreviousBuildAsReference: true
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-29 12:44:11 +00:00
|
|
|
stage('linting all') {
|
2018-11-22 09:15:08 +00:00
|
|
|
// perform a full linit if this is a merge forward and the change only lint passed.
|
|
|
|
when {
|
2018-12-19 07:31:16 +00:00
|
|
|
expression { return env.CHANGE_BRANCH =~ /(?i)^merge[._-]/ }
|
2018-11-22 09:15:08 +00:00
|
|
|
}
|
|
|
|
parallel {
|
2018-11-29 12:44:11 +00:00
|
|
|
stage('setup full') {
|
2018-11-22 09:15:08 +00:00
|
|
|
steps {
|
|
|
|
githubNotify credentialsId: 'test-jenkins-credentials',
|
2018-11-29 12:44:11 +00:00
|
|
|
description: 'Python lint on everything begins...',
|
2018-11-22 09:15:08 +00:00
|
|
|
status: 'PENDING',
|
|
|
|
context: "jenkins/pr/lint"
|
|
|
|
}
|
|
|
|
}
|
2018-11-29 12:44:11 +00:00
|
|
|
stage('lint salt full') {
|
2018-11-22 09:15:08 +00:00
|
|
|
steps {
|
|
|
|
sh '''
|
|
|
|
eval "$(pyenv init - --no-rehash)"
|
|
|
|
(tox -e pylint-salt ; echo "$?" > pylint-salt-full.exit) | tee pylint-report-salt-full.log
|
|
|
|
# remove color escape coding
|
|
|
|
sed -ri 's/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' pylint-report-salt-full.log
|
|
|
|
read rc_exit < pylint-salt-full.exit
|
|
|
|
exit "$rc_exit"
|
|
|
|
'''
|
|
|
|
}
|
|
|
|
}
|
2018-11-29 12:44:11 +00:00
|
|
|
stage('lint test full') {
|
2018-11-22 09:15:08 +00:00
|
|
|
steps {
|
|
|
|
sh '''
|
|
|
|
eval "$(pyenv init - --no-rehash)"
|
|
|
|
(tox -e pylint-tests ; echo "$?" > pylint-tests-full.exit) | tee pylint-report-tests-full.log
|
|
|
|
# remove color escape coding
|
|
|
|
sed -ri 's/\\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' pylint-report-tests-full.log
|
|
|
|
read rc_exit < pylint-tests-full.exit
|
|
|
|
exit "$rc_exit"
|
|
|
|
'''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
post {
|
|
|
|
always {
|
2018-11-30 12:36:07 +00:00
|
|
|
archiveArtifacts artifacts: 'pylint-report-*-full.log', allowEmptyArchive: true
|
2018-11-22 09:15:08 +00:00
|
|
|
step([$class: 'WarningsPublisher',
|
|
|
|
parserConfigurations: [[
|
|
|
|
parserName: 'PyLint',
|
2018-11-30 12:36:07 +00:00
|
|
|
pattern: 'pylint-report-*-full.log'
|
2018-11-22 09:15:08 +00:00
|
|
|
]],
|
|
|
|
failedTotalAll: '0',
|
|
|
|
useDeltaValues: false,
|
|
|
|
canRunOnFailed: true,
|
|
|
|
usePreviousBuildAsReference: true
|
|
|
|
])
|
|
|
|
}
|
|
|
|
}
|
2018-06-11 20:53:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
post {
|
2018-06-26 22:55:11 +00:00
|
|
|
always {
|
2018-06-29 18:07:08 +00:00
|
|
|
cleanWs()
|
2018-06-26 22:55:11 +00:00
|
|
|
}
|
2018-06-11 20:53:37 +00:00
|
|
|
success {
|
2018-06-19 20:58:38 +00:00
|
|
|
githubNotify credentialsId: 'test-jenkins-credentials',
|
2018-11-29 12:44:11 +00:00
|
|
|
description: 'Python lint test has passed',
|
2018-06-19 20:58:38 +00:00
|
|
|
status: 'SUCCESS',
|
|
|
|
context: "jenkins/pr/lint"
|
2018-06-11 20:53:37 +00:00
|
|
|
}
|
|
|
|
failure {
|
2018-06-19 20:58:38 +00:00
|
|
|
githubNotify credentialsId: 'test-jenkins-credentials',
|
2018-11-29 12:44:11 +00:00
|
|
|
description: 'Python lint test has failed',
|
2018-06-19 20:58:38 +00:00
|
|
|
status: 'FAILURE',
|
|
|
|
context: "jenkins/pr/lint"
|
2018-10-05 14:46:15 +00:00
|
|
|
slackSend channel: "#jenkins-prod-pr",
|
|
|
|
color: '#FF0000',
|
|
|
|
message: "FAILED: PR-Job: '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})"
|
2018-06-11 20:53:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|