Files
hello-codeartifact/Jenkinsfile
2025-06-29 17:58:23 +00:00

107 lines
2.3 KiB
Groovy

pipeline {
agent any
environment {
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')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Setup') {
steps {
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
'''
}
}
}
}
stage('Build') {
steps {
script {
docker.image(env.BUILD_IMAGE).inside {
sh '''
python -m build
'''
}
}
}
}
stage('Test') {
steps {
script {
docker.image(env.BUILD_IMAGE).inside {
sh '''
python -m pytest tests/ --junitxml=test-results.xml || true
'''
}
}
}
post {
always {
// Publish test results if they exist
script {
if (fileExists('test-results.xml')) {
publishTestResults testResultsPattern: 'test-results.xml'
}
}
}
}
}
stage('Publish') {
steps {
script {
docker.image(env.BUILD_IMAGE).inside('-e HOME=/tmp') {
sh '''
# Configure twine for CodeArtifact in /tmp
cat > /tmp/.pypirc <<EOF
[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
twine upload --config-file /tmp/.pypirc --repository codeartifact dist/*
'''
}
}
}
}
}
post {
always {
// Archive build artifacts
archiveArtifacts artifacts: 'dist/**', fingerprint: true, allowEmptyArchive: true
}
success {
echo 'Pipeline completed successfully!'
}
failure {
echo 'Pipeline failed!'
}
}
}