Files
hello-codeartifact/Jenkinsfile

107 lines
2.3 KiB
Plaintext
Raw Normal View History

2025-06-29 15:39:27 +00:00
pipeline {
agent any
2025-06-29 16:25:36 +00:00
2025-06-29 15:39:27 +00:00
environment {
2025-06-29 17:58:23 +00:00
BUILD_IMAGE = 'python:3.9-slim'
AWS_REGION = 'us-east-1'
AWS_ACCOUNT_ID = '123456789012'
CODEART_DOMAIN = 'jacquesingram'
CODEART_REPO = 'hello-codeartifact'
CODEART_TOKEN = credentials('codeartifact-token')
2025-06-29 16:25:36 +00:00
}
2025-06-29 15:39:27 +00:00
stages {
stage('Checkout') {
steps {
checkout scm
}
}
2025-06-29 16:25:36 +00:00
2025-06-29 17:58:23 +00:00
stage('Setup') {
2025-06-29 15:39:27 +00:00
steps {
2025-06-29 17:58:23 +00:00
script {
docker.image(env.BUILD_IMAGE).inside {
sh '''
pip install --upgrade pip
pip install build twine pytest
if [ -f requirements.txt ]; then
pip install -r requirements.txt
fi
'''
2025-06-29 15:39:27 +00:00
}
}
}
}
2025-06-29 16:25:36 +00:00
2025-06-29 15:49:37 +00:00
stage('Build') {
2025-06-29 15:39:27 +00:00
steps {
2025-06-29 16:25:36 +00:00
script {
2025-06-29 17:58:23 +00:00
docker.image(env.BUILD_IMAGE).inside {
2025-06-29 16:25:36 +00:00
sh '''
2025-06-29 17:58:23 +00:00
python -m build
2025-06-29 16:25:36 +00:00
'''
}
}
}
}
stage('Test') {
2025-06-29 15:39:27 +00:00
steps {
2025-06-29 16:25:36 +00:00
script {
2025-06-29 17:58:23 +00:00
docker.image(env.BUILD_IMAGE).inside {
2025-06-29 16:25:36 +00:00
sh '''
2025-06-29 17:58:23 +00:00
python -m pytest tests/ --junitxml=test-results.xml || true
2025-06-29 16:25:36 +00:00
'''
}
}
}
post {
always {
2025-06-29 16:41:55 +00:00
// Publish test results if they exist
script {
if (fileExists('test-results.xml')) {
publishTestResults testResultsPattern: 'test-results.xml'
}
}
2025-06-29 16:25:36 +00:00
}
2025-06-29 15:39:27 +00:00
}
}
2025-06-29 16:25:36 +00:00
2025-06-29 17:54:26 +00:00
stage('Publish') {
2025-06-29 15:49:37 +00:00
steps {
2025-06-29 16:25:36 +00:00
script {
2025-06-29 16:35:38 +00:00
docker.image(env.BUILD_IMAGE).inside('-e HOME=/tmp') {
2025-06-29 16:25:36 +00:00
sh '''
2025-06-29 16:35:38 +00:00
# Configure twine for CodeArtifact in /tmp
cat > /tmp/.pypirc <<EOF
2025-06-29 16:25:36 +00:00
[distutils]
index-servers = codeartifact
[codeartifact]
repository = https://${CODEART_DOMAIN}-${AWS_ACCOUNT_ID}.d.codeartifact.${AWS_REGION}.amazonaws.com/pypi/${CODEART_REPO}/
username = aws
password = ${CODEART_TOKEN}
EOF
# Publish to CodeArtifact
2025-06-29 16:35:38 +00:00
twine upload --config-file /tmp/.pypirc --repository codeartifact dist/*
2025-06-29 16:25:36 +00:00
'''
}
}
2025-06-29 15:49:37 +00:00
}
}
2025-06-29 17:58:23 +00:00
}
2025-06-29 16:25:36 +00:00
2025-06-29 15:39:27 +00:00
post {
2025-06-29 16:25:36 +00:00
always {
// Archive build artifacts
2025-06-29 17:58:23 +00:00
archiveArtifacts artifacts: 'dist/**', fingerprint: true, allowEmptyArchive: true
2025-06-29 16:25:36 +00:00
}
2025-06-29 15:39:27 +00:00
success {
2025-06-29 17:58:23 +00:00
echo 'Pipeline completed successfully!'
2025-06-29 15:39:27 +00:00
}
failure {
2025-06-29 17:58:23 +00:00
echo 'Pipeline failed!'
2025-06-29 15:39:27 +00:00
}
2025-06-29 17:58:23 +00:00
}
}