pipeline { agent any environment { GITEA_CREDS = credentials('AMARILLO-JENKINS-GITEA-USER') TWINE_REPO_URL = "https://git.gerhardt.io/api/packages/amarillo/pypi" REGISTRY_URL = 'git.gerhardt.io' OWNER = 'amarillo' IMAGE_NAME = "amarillo" TAG = 'latest' } stages { stage('Create virtual environment') { steps { echo 'Creating virtual environment' sh '''python3 -m venv .venv . .venv/bin/activate''' } } stage('Installing requirements') { steps { echo 'Installing packages' sh 'python3 -m pip install -r requirements.txt' sh 'python3 -m pip install --upgrade build' sh 'python3 -m pip install --upgrade twine' } } stage('Test') { steps { echo 'Testing' } } stage('Build package') { steps { echo 'Building package' sh 'python3 -m build' } } stage('Publish package') { steps { sh 'python3 -m twine upload --skip-existing --verbose --repository-url $TWINE_REPO_URL --username $GITEA_CREDS_USR --password $GITEA_CREDS_PSW ./dist/*' } } stage('Install docker') { steps { echo 'Installing docker' sh 'curl -fsSl https://get.docker.com | sh' echo 'Starting docker daemon' sh 'systemctl start docker' } } stage('Build docker image') { steps { echo 'Building image' script { docker.build("${OWNER}/${IMAGE_NAME}:${TAG}") } } } stage('Push image to container registry') { steps { echo 'Pushing image to registry' script { docker.withRegistry(REGISTRY_URL, GITEA_CREDS){ docker.image("${OWNER}/${IMAGE_NAME}:${TAG}").push() } } } } } post { always { echo 'This will always run' } success { echo 'This will run only if successful' } failure { echo 'This will run only if failed' } unstable { echo 'This will run only if the run was marked as unstable' } changed { echo 'This will run only if the state of the Pipeline has changed' echo 'For example, if the Pipeline was previously failing but is now successful' } } }