Created
June 24, 2022 13:20
-
-
Save jgoos/aa9fa3a83829b7a559930acaccc0d2e4 to your computer and use it in GitHub Desktop.
To test ansible roles via Jenkins using molecule and podman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pipeline { | |
agent any | |
stages { | |
stage('Create ENV') { | |
steps { | |
sh ''' | |
# Remove we do not have local collections | |
rm -rf $HOME/.ansible | |
# Initialize new venv | |
python3.8 -m venv venv | |
# Update pip | |
source venv/bin/activate | |
python -m pip install --upgrade pip wheel | |
python -m pip install "molecule[lint,podman]" ansible-core yamllint ansible-lint flake8 | |
''' | |
} | |
} | |
stage('Show versions') { | |
parallel { | |
stage('Show versions') { | |
steps { | |
sh ''' | |
source venv/bin/activate | |
podman -v | |
python -V | |
ansible --version | |
molecule --version | |
''' | |
} | |
} | |
stage('What') { | |
steps { | |
sh 'ls -fla' | |
} | |
} | |
} | |
} | |
stage('Molecule lint') { | |
parallel { | |
stage('Molecule lint') { | |
steps { | |
sh ''' | |
source venv/bin/activate | |
pwd | |
cd ansible_code | |
molecule lint | |
''' | |
} | |
} | |
stage('Install Collections') { | |
steps { | |
sh 'ansible-galaxy collection install containers.podman' | |
} | |
} | |
} | |
} | |
stage('Molecule test') { | |
steps { | |
sh ''' | |
source venv/bin/activate | |
cd ansible_code | |
export PLATFORM_NAME="$(uuidgen)" | |
mkdir -p "${MOLECULE_PROJECT_DIRECTORY}/tmp/${PLATFORM_NAME}" | |
export MOLECULE_EPHEMERAL_DIRECTORY="${MOLECULE_PROJECT_DIRECTORY}/tmp/${PLATFORM_NAME}" | |
molecule test | |
''' | |
} | |
} | |
} | |
environment { | |
PY_COLORS = 1 | |
ANSIBLE_FORCE_COLOR = 1 | |
} | |
post { | |
always { | |
cleanWs(cleanWhenNotBuilt: false, deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true, patterns: [[pattern: '.gitignore', type: 'INCLUDE'], | |
[pattern: '.propsfile', type: 'EXCLUDE']]) | |
} | |
} | |
options { | |
checkoutToSubdirectory('ansible_code') | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment