pungi/tests/Jenkinsfile
Lubomír Sedlář 7a4bd62978 Fix jenkins tests
Defining a variable on top level is now causing the pipeline to not
execute anything and just report success.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
(cherry picked from commit 912baf119879e8d5b113e64b9a98e169ef3aa516)
2025-09-29 18:28:02 +03:00

58 lines
2.5 KiB
Groovy

pipeline {
agent {
label 'cico-workspace'
}
parameters {
string(name: 'REPO', defaultValue: '', description: 'Git repo URL where the pull request from')
string(name: 'BRANCH', defaultValue: '', description: 'Git branch where the pull request from')
}
stages {
stage('CI') {
steps {
script {
if (params.REPO == "" || params.BRANCH == "") {
error "Please supply both params (REPO and BRANCH)"
}
def DUFFY_SESSION_ID
try {
echo "Requesting duffy node ..."
def session_str = sh returnStdout: true, script: "set +x; duffy client --url https://duffy.ci.centos.org/api/v1 --auth-name fedora-infra --auth-key $CICO_API_KEY request-session pool=virt-ec2-t2-centos-9s-x86_64,quantity=1"
def session = readJSON text: session_str
DUFFY_SESSION_ID= session.session.id
def hostname = session.session.nodes[0].hostname
echo "duffy session id: $DUFFY_SESSION_ID hostname: $hostname"
def remote_dir = "/tmp/$JENKINS_AGENT_NAME"
echo "remote_dir: $remote_dir"
writeFile file: 'job.sh', text: """
set -xe
dnf install -y git podman
git config --global user.email "jenkins@localhost"
git config --global user.name "jenkins"
cd $remote_dir
git clone https://pagure.io/pungi.git -b master
cd pungi
git remote rm proposed || true
git remote add proposed "$params.REPO"
git fetch proposed
git checkout origin/master
git merge --no-ff "proposed/$params.BRANCH" -m "Merge PR"
podman run --rm -v .:/src:Z quay.io/exd-guild-compose/pungi-test tox -r -e flake8,black,py3,bandit
"""
sh "cat job.sh"
sh "ssh -o StrictHostKeyChecking=no root@$hostname mkdir $remote_dir"
sh "scp job.sh root@$hostname:$remote_dir"
sh "ssh root@$hostname sh $remote_dir/job.sh"
} finally {
if (DUFFY_SESSION_ID) {
echo "Release duffy node ..."
sh "set +x; duffy client --url https://duffy.ci.centos.org/api/v1 --auth-name fedora-infra --auth-key $CICO_API_KEY retire-session $DUFFY_SESSION_ID > /dev/null"
}
}
}
}
}
}
}