Files
hello-codeartifact/Jenkinsfile

79 lines
2.4 KiB
Plaintext
Raw Normal View History

2025-06-29 15:39:27 +00:00
pipeline {
agent any
environment {
2025-06-29 15:49:37 +00:00
// Non-secret config injected from Jenkins Credentials (Secret Text)
2025-06-29 15:39:27 +00:00
AWS_REGION = credentials('AWS_REGION')
AWS_ACCOUNT_ID = credentials('AWS_ACCOUNT_ID')
CODEART_DOMAIN = credentials('CODEART_DOMAIN')
CODEART_REPO = credentials('CODEART_REPO')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Authenticate & Configure') {
steps {
2025-06-29 16:12:42 +00:00
// Use AWS Steps Plugin to pick up your IAM user keys
withAWS(credentials: 'jenkins-codeartifact', region: "${AWS_REGION}") {
2025-06-29 15:39:27 +00:00
script {
2025-06-29 15:49:37 +00:00
// Fetch a short-lived CodeArtifact token
2025-06-29 15:39:27 +00:00
env.CODEART_TOKEN = sh(
script: """
aws codeartifact get-authorization-token \\
--domain ${CODEART_DOMAIN} \\
--domain-owner ${AWS_ACCOUNT_ID} \\
--query authorizationToken --output text
""", returnStdout: true
).trim()
}
// Point pip and twine at your CodeArtifact repo
sh '''
pip config set global.index-url \
"https://aws:${CODEART_TOKEN}@${CODEART_DOMAIN}-${AWS_ACCOUNT_ID}.d.codeartifact.${AWS_REGION}.amazonaws.com/pypi/${CODEART_REPO}/simple/"
cat > ~/.pypirc <<EOF
2025-06-29 15:49:37 +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}
2025-06-29 15:39:27 +00:00
EOF
'''
}
}
}
2025-06-29 15:49:37 +00:00
stage('Build') {
2025-06-29 15:39:27 +00:00
steps {
sh '''
python3 -m pip install --upgrade setuptools wheel twine
python3 setup.py sdist bdist_wheel
'''
}
}
2025-06-29 15:49:37 +00:00
stage('Trivy Security Scan') {
2025-06-29 15:39:27 +00:00
steps {
// Runs Trivy as a Docker container against your workspace
2025-06-29 15:49:37 +00:00
// This will fail the build if HIGH or CRITICAL vulnerabilities are found
2025-06-29 15:39:27 +00:00
sh 'docker run --rm -v ${WORKSPACE}:/project aquasec/trivy:latest fs --severity HIGH,CRITICAL --exit-code 1 /project'
}
}
2025-06-29 15:49:37 +00:00
stage('Publish') {
steps {
// Only publish if security scan passes
sh '''
twine upload --repository codeartifact dist/*
'''
}
}
2025-06-29 15:39:27 +00:00
}
post {
success {
echo '✅ Build succeeded and package published to CodeArtifact.'
}
failure {
echo '❌ Build failed — check the console output for errors.'
}
}
2025-06-29 15:49:37 +00:00
}