This repository has been archived by the owner on Sep 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consistent formating and container registry for Jenkinsfiles.
- Loading branch information
Showing
5 changed files
with
96 additions
and
90 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
tab_width = 2 | ||
insert_final_newline = true |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[*.py] | ||
indent_size = 4 | ||
tab_width = 4 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,107 +1,108 @@ | ||
pipeline { | ||
agent { | ||
kubernetes { | ||
yaml """ | ||
apiVersion: v1 | ||
kind: Pod | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- name: build | ||
image: python:3.11-alpine | ||
command: ['tail', '-f', '/dev/null'] | ||
""" | ||
} | ||
agent { | ||
kubernetes { | ||
yaml """ | ||
apiVersion: v1 | ||
kind: Pod | ||
spec: | ||
restartPolicy: Never | ||
containers: | ||
- name: build | ||
image: artifactory.cloud.cms.gov/docker/python:3.11-alpine | ||
command: ['tail', '-f', '/dev/null'] | ||
""" | ||
} | ||
} | ||
|
||
environment { | ||
TARGET_DIR = "python-server" | ||
LINT_ARGS = "--disable=missing-docstring --disable=invalid-name" | ||
} | ||
environment { | ||
TARGET_DIR = "python-server" | ||
LINT_ARGS = "--disable=missing-docstring --disable=invalid-name" | ||
} | ||
|
||
options { | ||
buildDiscarder(logRotator(daysToKeepStr: '1', numToKeepStr: '10')) | ||
} | ||
|
||
options { | ||
buildDiscarder(logRotator(daysToKeepStr: '1', numToKeepStr: '10')) | ||
stages { | ||
stage('Build Python') { | ||
steps { | ||
container('build') { | ||
sh 'python -m pip install --upgrade pip' | ||
dir("${TARGET_DIR}") { | ||
sh ''' | ||
pip install -r requirements-dev.txt | ||
''' | ||
} | ||
} | ||
} | ||
} | ||
|
||
stages{ | ||
stage('Build Python') { | ||
stage('Test & Lint') { | ||
parallel { | ||
stage('Test') { | ||
steps { | ||
container('build') { | ||
sh 'python -m pip install --upgrade pip' | ||
dir("${TARGET_DIR}") { | ||
sh ''' | ||
pip install -r requirements-dev.txt | ||
python -m coverage --version | ||
python -m coverage run -m pytest | ||
python -m coverage report | ||
python -m coverage xml | ||
''' | ||
archiveArtifacts artifacts: "coverage.xml", allowEmptyArchive: true | ||
} | ||
} | ||
} | ||
} | ||
stage('Test & Lint'){ | ||
parallel { | ||
stage('Test') { | ||
steps { | ||
container('build') { | ||
dir("${TARGET_DIR}") { | ||
sh ''' | ||
python -m coverage --version | ||
python -m coverage run -m pytest | ||
python -m coverage report | ||
python -m coverage xml | ||
''' | ||
archiveArtifacts artifacts: "coverage.xml", allowEmptyArchive: true | ||
} | ||
} | ||
} | ||
} | ||
stage('Lint') { | ||
steps { | ||
catchError (buildResult: currentBuild.currentResult, stageResult: 'UNSTABLE') { | ||
container('build') { | ||
dir("${TARGET_DIR}") { | ||
sh ''' | ||
echo "Linting '${TARGET_DIR}' with arguments '${LINT_ARGS}'" | ||
python -m pylint --version | ||
find . -type f -iname "*.py" | grep -vE ".cache" | xargs python -m pylint ${LINT_ARGS} | ||
''' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
stage('SAST') { | ||
steps { | ||
script { | ||
def sastParameters = [ | ||
string(name: 'git_repository', value: "${scm.userRemoteConfigs[0].url}"), | ||
string(name: 'git_credentials', value: "${scm.userRemoteConfigs[0].credentialsId}"), | ||
string(name: 'git_commit', value: "${GIT_COMMIT}"), | ||
string(name: 'git_branch', value: "${env.GIT_BRANCH}"), | ||
] | ||
|
||
if (env.CHANGE_ID) { | ||
sastParameters.add(string(name: 'git_change_id', value: "${env.CHANGE_ID}")) | ||
} | ||
|
||
build(job: 'Python Server SAST', wait: true, propagate: true, parameters: sastParameters) | ||
} | ||
} | ||
stage('Lint') { | ||
steps { | ||
catchError (buildResult: currentBuild.currentResult, stageResult: 'UNSTABLE') { | ||
container('build') { | ||
dir("${TARGET_DIR}") { | ||
sh ''' | ||
echo "Linting '${TARGET_DIR}' with arguments '${LINT_ARGS}'" | ||
python -m pylint --version | ||
find . -type f -iname "*.py" | grep -vE ".cache" | xargs python -m pylint ${LINT_ARGS} | ||
''' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
stage('Delivery') { | ||
steps { | ||
build(job: 'Python Server Delivery', wait: true, propagate: true, parameters: [ | ||
string(name: 'tag', value: "${GIT_COMMIT[0..7]}"), | ||
string(name: 'git_repository', value: "${scm.userRemoteConfigs[0].url}"), | ||
string(name: 'git_credentials', value: "${scm.userRemoteConfigs[0].credentialsId}"), | ||
string(name: 'git_commit', value: "${GIT_COMMIT}"), | ||
string(name: 'build_dir', value: 'python-server'), | ||
string(name: 'dockerfile', value: 'python-server/Dockerfile') | ||
]) | ||
container('build') { | ||
echo 'Child pipeline completed' | ||
} | ||
|
||
stage('SAST') { | ||
steps { | ||
script { | ||
def sastParameters = [ | ||
string(name: 'git_repository', value: "${scm.userRemoteConfigs[0].url}"), | ||
string(name: 'git_credentials', value: "${scm.userRemoteConfigs[0].credentialsId}"), | ||
string(name: 'git_commit', value: "${GIT_COMMIT}"), | ||
string(name: 'git_branch', value: "${env.GIT_BRANCH}"), | ||
] | ||
|
||
if (env.CHANGE_ID) { | ||
sastParameters.add(string(name: 'git_change_id', value: "${env.CHANGE_ID}")) | ||
} | ||
|
||
build(job: 'Python Server SAST', wait: true, propagate: true, parameters: sastParameters) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
stage('Delivery') { | ||
steps { | ||
build(job: 'Python Server Delivery', wait: true, propagate: true, parameters: [ | ||
string(name: 'tag', value: "${GIT_COMMIT[0..7]}"), | ||
string(name: 'git_repository', value: "${scm.userRemoteConfigs[0].url}"), | ||
string(name: 'git_credentials', value: "${scm.userRemoteConfigs[0].credentialsId}"), | ||
string(name: 'git_commit', value: "${GIT_COMMIT}"), | ||
string(name: 'build_dir', value: 'python-server'), | ||
string(name: 'dockerfile', value: 'python-server/Dockerfile') | ||
]) | ||
} | ||
} | ||
} | ||
} |