From d62129f9213ca288175f0ede7dbfdc0923ec34c2 Mon Sep 17 00:00:00 2001 From: Haibo Lin Date: Aug 29 2022 08:31:49 +0000 Subject: Add Jenkinsfile for CI JIRA: RHELCMP-9800 Signed-off-by: Haibo Lin --- diff --git a/tests/Jenkinsfile b/tests/Jenkinsfile new file mode 100644 index 0000000..636a515 --- /dev/null +++ b/tests/Jenkinsfile @@ -0,0 +1,58 @@ +def DUFFY_SESSION_ID + +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)" + } + 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/cts.git -b master +cd cts +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/cts-test tox -r + """ + 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" + } + } + } + } + } + } +}