From 17ef88c9bf93bcb6fc789ac5a5ea67eb1f553af0 Mon Sep 17 00:00:00 2001 From: Vito Di Benedetto <55766483+vitodb@users.noreply.github.com> Date: Wed, 27 Sep 2023 23:52:39 -0500 Subject: [PATCH] Adding Jenkinsfile for EL9 --- .Jenkins/workflows/Jenkinsfile_EL9 | 154 +++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 .Jenkins/workflows/Jenkinsfile_EL9 diff --git a/.Jenkins/workflows/Jenkinsfile_EL9 b/.Jenkins/workflows/Jenkinsfile_EL9 new file mode 100644 index 00000000..919369b6 --- /dev/null +++ b/.Jenkins/workflows/Jenkinsfile_EL9 @@ -0,0 +1,154 @@ +// SPDX-FileCopyrightText: 2017 Fermi Research Alliance, LLC +// SPDX-License-Identifier: Apache-2.0 + +pipeline { + agent { label 'docker' } + stages{ + stage('DE modules tests') { + parallel { + stage('flake8') { + agent { + node { + label 'docker' + customWorkspace "${WORKSPACE}/${STAGE_NAME}" + } + } + options { + timeout(time: "${STAGE_TIMEOUT}", activity: false, unit: 'MINUTES') + } + steps { + script { + // DOCKER_IMAGE is defined through Jenkins project + flake8StageDockerImage="${DOCKER_IMAGE}_${BUILD_NUMBER}_${STAGE_NAME}" + // Set custom Build Name + if (params.GITHUB_PR_NUMBER) { + if (params.GITHUB_PR_STATE == 'CLOSED') { + currentBuild.displayName="${BUILD_NUMBER}#${EL_VERSION}#PR#${GITHUB_PR_NUMBER}#CLOSED" + } else { + currentBuild.displayName="${BUILD_NUMBER}#${EL_VERSION}#PR#${GITHUB_PR_NUMBER}" + } + } else { + currentBuild.displayName="${BUILD_NUMBER}#${BRANCH}" + } + } + echo "cleanup workspace" + sh 'for f in $(ls -A); do rm -rf ${f}; done' + // DE_MOD_REPO is defined through Jenkins project + echo "clone decisionengine_modules code from ${DE_MOD_REPO}" + sh ''' + git clone ${DE_MOD_REPO} + cd decisionengine_modules + echo "checkout ${BRANCH} branch" + git checkout ${BRANCH} + echo GITHUB_PR_NUMBER: ${GITHUB_PR_NUMBER} - GITHUB_PR_STATE: ${GITHUB_PR_STATE} + if [[ -n ${GITHUB_PR_NUMBER} && ${GITHUB_PR_STATE} == OPEN ]]; then + git fetch origin pull/${GITHUB_PR_NUMBER}/merge:merge${GITHUB_PR_NUMBER} + git checkout merge${GITHUB_PR_NUMBER} + fi + cd .. + ''' + echo "prepare docker image ${flake8StageDockerImage}" + sh "docker build --pull --tag ${flake8StageDockerImage} --build-arg BASEIMAGE=hepcloud/decision-engine-ci-el9:${BRANCH} --build-arg UID=\$(id -u) --build-arg GID=\$(id -g) -f decisionengine_modules/package/ci/EL9/Dockerfile decisionengine_modules/package/ci/EL9/" + echo "Run ${STAGE_NAME} tests" + sh "docker run --rm --env GITHUB_PR_NUMBER=${GITHUB_PR_NUMBER} --env PYTEST_TIMEOUT=${PYTEST_TIMEOUT} -v ${WORKSPACE}/decisionengine_modules:${WORKSPACE}/decisionengine_modules -w ${WORKSPACE}/decisionengine_modules ${flake8StageDockerImage} \"-m pytest -m flake8 --flake8\" \"flake8.log\" \"${BRANCH}\"" + } + post { + always { + archiveArtifacts artifacts: "decisionengine_modules/flake8.log" + echo "cleanup docker image ${flake8StageDockerImage}" + sh "docker rmi ${flake8StageDockerImage}" + } + } + } + stage('unit_tests') { + agent { + node { + label 'docker' + customWorkspace "${WORKSPACE}/${STAGE_NAME}" + } + } + options { + timeout(time: "${STAGE_TIMEOUT}", activity: false, unit: 'MINUTES') + } + steps { + script { + // DOCKER_IMAGE is defined through Jenkins project + unit_testsStageDockerImage="${DOCKER_IMAGE}_${BUILD_NUMBER}_${STAGE_NAME}" + } + echo "cleanup workspace" + sh 'for f in $(ls -A); do rm -rf ${f}; done' + // DE_MOD_REPO is defined through Jenkins project + echo "clone decisionengine_modules code from ${DE_MOD_REPO}" + sh ''' + git clone ${DE_MOD_REPO} + cd decisionengine_modules + echo "checkout ${BRANCH} branch" + git checkout ${BRANCH} + echo GITHUB_PR_NUMBER: ${GITHUB_PR_NUMBER} - GITHUB_PR_STATE: ${GITHUB_PR_STATE} + if [[ -n ${GITHUB_PR_NUMBER} && ${GITHUB_PR_STATE} == OPEN ]]; then + git fetch origin pull/${GITHUB_PR_NUMBER}/merge:merge${GITHUB_PR_NUMBER} + git checkout merge${GITHUB_PR_NUMBER} + fi + cd .. + ''' + echo "prepare docker image ${unit_testsStageDockerImage}" + sh "docker build --pull --tag ${unit_testsStageDockerImage} --build-arg BASEIMAGE=hepcloud/decision-engine-ci-el9:${BRANCH} --build-arg UID=\$(id -u) --build-arg GID=\$(id -g) -f decisionengine_modules/package/ci/EL9/Dockerfile decisionengine_modules/package/ci/EL9/" + echo "Run ${STAGE_NAME} tests" + sh "docker run --rm --env GITHUB_PR_NUMBER=${GITHUB_PR_NUMBER} --env PYTEST_TIMEOUT=${PYTEST_TIMEOUT} -v ${WORKSPACE}/decisionengine_modules:${WORKSPACE}/decisionengine_modules -w ${WORKSPACE}/decisionengine_modules ${unit_testsStageDockerImage} \"-m pytest --cov-report term --cov=decisionengine_modules --no-cov-on-fail\" \"pytest.log\" \"${BRANCH}\"" + } + post { + always { + archiveArtifacts artifacts: "decisionengine_modules/pytest.log" + echo "cleanup docker image ${unit_testsStageDockerImage}" + sh "docker rmi ${unit_testsStageDockerImage}" + } + } + } + stage('rpmbuild') { + agent { + node { + label 'docker' + customWorkspace "${WORKSPACE}/${STAGE_NAME}" + } + } + options { + timeout(time: "${STAGE_TIMEOUT}", activity: false, unit: 'MINUTES') + } + steps { + script { + // DOCKER_IMAGE is defined through Jenkins project + rpmbuildStageDockerImage="${DOCKER_IMAGE}_${BUILD_NUMBER}_${STAGE_NAME}" + } + echo "cleanup workspace" + sh 'for f in $(ls -A); do rm -rf ${f}; done' + // DE_MOD_REPO is defined through Jenkins project + echo "clone decisionengine_modules code from ${DE_MOD_REPO}" + sh ''' + git clone ${DE_MOD_REPO} + cd decisionengine_modules + echo "checkout ${BRANCH} branch" + git checkout ${BRANCH} + echo GITHUB_PR_NUMBER: ${GITHUB_PR_NUMBER} - GITHUB_PR_STATE: ${GITHUB_PR_STATE} + if [[ -n ${GITHUB_PR_NUMBER} && ${GITHUB_PR_STATE} == OPEN ]]; then + git fetch origin pull/${GITHUB_PR_NUMBER}/merge:merge${GITHUB_PR_NUMBER} + git checkout merge${GITHUB_PR_NUMBER} + fi + cd .. + ''' + echo "prepare docker image ${rpmbuildStageDockerImage}" + sh "docker build --pull --tag ${rpmbuildStageDockerImage} --build-arg BASEIMAGE=hepcloud/decision-engine-ci-el9:${BRANCH} --build-arg UID=\$(id -u) --build-arg GID=\$(id -g) -f decisionengine_modules/package/ci/EL9/Dockerfile decisionengine_modules/package/ci/EL9/" + echo "Run ${STAGE_NAME} tests" + sh "docker run --rm --env GITHUB_PR_NUMBER=${GITHUB_PR_NUMBER} --env PYTEST_TIMEOUT=${PYTEST_TIMEOUT} -v ${WORKSPACE}/decisionengine_modules:${WORKSPACE}/decisionengine_modules -w ${WORKSPACE}/decisionengine_modules ${rpmbuildStageDockerImage} \"setup.py bdist_rpm\" \"rpmbuild.log\" \"${BRANCH}\"" + } + post { + always { + archiveArtifacts artifacts: "decisionengine_modules/rpmbuild.log,decisionengine_modules/dist/*.rpm" + echo "cleanup docker image ${rpmbuildStageDockerImage}" + sh "docker rmi ${rpmbuildStageDockerImage}" + } + } + } + } + } + } +}