diff --git a/Jenkinsfile b/Jenkinsfile index 0e4a468..3eeddd0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,79 +1,200 @@ pipeline { agent any + environment { // Non-secret config injected from Jenkins Credentials (Secret Text) AWS_REGION = credentials('AWS_REGION') AWS_ACCOUNT_ID = credentials('AWS_ACCOUNT_ID') CODEART_DOMAIN = credentials('CODEART_DOMAIN') CODEART_REPO = credentials('CODEART_REPO') + + // Build configuration + PYTHON_VERSION = '3.11-slim' + BUILD_IMAGE = "python:${PYTHON_VERSION}" } + + options { + // Prevent concurrent builds + disableConcurrentBuilds() + // Keep build logs for audit + buildDiscarder(logRotator(numToKeepStr: '50')) + // Timeout protection + timeout(time: 30, unit: 'MINUTES') + } + stages { stage('Checkout') { steps { checkout scm } } + stage('Authenticate & Configure') { steps { - // Use AWS Steps Plugin to pick up your IAM user keys - withAWS(credentials: 'jenkins-codeartifact', region: "${AWS_REGION}") { + withAWS(credentials: 'jenkins-codeartifact', region: env.AWS_REGION) { script { // Fetch a short-lived CodeArtifact token env.CODEART_TOKEN = sh( script: """ aws codeartifact get-authorization-token \\ - --domain ${CODEART_DOMAIN} \\ - --domain-owner ${AWS_ACCOUNT_ID} \\ + --domain ${env.CODEART_DOMAIN} \\ + --domain-owner ${env.AWS_ACCOUNT_ID} \\ --query authorizationToken --output text """, returnStdout: true ).trim() + + // Store repository URL for Docker container + env.CODEART_URL = "https://aws:${env.CODEART_TOKEN}@${env.CODEART_DOMAIN}-${env.AWS_ACCOUNT_ID}.d.codeartifact.${env.AWS_REGION}.amazonaws.com/pypi/${env.CODEART_REPO}/simple/" } - // 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 < ~/.pypirc <