Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
Consistent formating and container registry for Jenkinsfiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
sflanker committed Jul 2, 2024
1 parent 7d0a1d1 commit 072257d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 90 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
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
3 changes: 0 additions & 3 deletions angular-ui/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ pipeline {
string(name: 'build_dir', value: 'angular-ui'),
string(name: 'dockerfile', value: 'angular-ui/Dockerfile')
])
container('build') {
echo 'Child pipeline completed'
}
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions go-server/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ pipeline {
string(name: 'build_dir', value: 'go-server'),
string(name: 'dockerfile', value: 'go-server/Dockerfile')
])
container('build') {
echo 'Child pipeline completed'
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions python-server/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.py]
indent_size = 4
tab_width = 4
169 changes: 85 additions & 84 deletions python-server/Jenkinsfile
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')
])
}
}
}
}

0 comments on commit 072257d

Please sign in to comment.