diff --git a/Jenkinsfile b/Jenkinsfile index a9561e1..fa7505c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -84,41 +84,31 @@ pipeline { environment { KOJI_KEYTAB = credentials('fedora-keytab') KRB_PRINCIPAL = 'bpeck/jenkins-continuous-infra.apps.ci.centos.org@FEDORAPROJECT.ORG' - REPO_FULL_NAME = "${params.REPO_FULL_NAME}" - SOURCE_REPO_FULL_NAME = "${sourceRepo}" - REPO_NAME = "${params.REPO_FULL_NAME.split('/')[1]}" - RELEASE_ID = "${releaseId}" - PR_ID = "${params.PR_ID}" - PR_UID = "${params.PR_UID}" - PR_COMMIT = "${params.PR_COMMIT}" - PR_COMMENT = "${params.PR_COMMENT}" - RAWHIDE_RELEASE_ID = "${FEDORA_CI_RAWHIDE_RELEASE_ID}" } steps { script { timeout(time: 240, unit: 'MINUTES') { - // lock buildroot - lock("${env.NODE_NAME}-mock-buildroot") { - def rc = sh(returnStatus: true, script: './pullRequest2scratchBuild.sh') - if (fileExists('koji_url')) { - kojiUrl = readFile("${env.WORKSPACE}/koji_url").trim() - } - if (fileExists('task_id')) { - taskId = readFile("${env.WORKSPACE}/task_id").trim() - } - if (!kojiUrl || !taskId) { - error('Failed to submit a scratch-build') + def rc = sh(returnStatus: true, script: "./scratch-build.sh koji ${releaseId}-candidate git+https://src.fedoraproject.org/${sourceRepo}.git#${params.PR_COMMIT}") + if (fileExists('koji_url')) { + kojiUrl = readFile("${env.WORKSPACE}/koji_url").trim() + } + if (fileExists('task_id')) { + taskId = readFile("${env.WORKSPACE}/task_id").trim() + } + catchError(buildResult: 'UNSTABLE') { + if (rc != 0) { + error('Failed to scratch build the pull request.') } } - } - sendMessage(type: 'running', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl) + sendMessage(type: 'running', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl) - // Wait for the scratch-build to finish - def rc = sh(returnStatus: true, script: "./wait-build.sh ${taskId}") - catchError(buildResult: 'UNSTABLE') { - if (rc != 0) { - error("Scratch-build failed in Koji") + // Wait for the scratch-build to finish + rc = sh(returnStatus: true, script: "./wait-build.sh ${taskId}") + catchError(buildResult: 'UNSTABLE') { + if (rc != 0) { + error("Scratch-build failed in Koji") + } } } } @@ -130,6 +120,16 @@ pipeline { success { sendMessage(type: 'complete', artifactId: artifactId, pipelineMetadata: pipelineMetadata, dryRun: isPullRequest(), runUrl: kojiUrl) + // Run dist-git tests on the scratch build, and report results back to the pull request + build( + wait: false, + job: 'fedora-ci/dist-git-pipeline/master', + parameters: [ + string(name: 'ARTIFACT_ID', value: "(koji-build:${taskId})->${artifactId}"), + string(name: 'TEST_PROFILE', value: releaseId) + ] + ) + // Run the installability test on the scratch build, and report results back to the pull request build( wait: false, diff --git a/README.md b/README.md index 36f77e6..7598d5f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ # dist-git build pipeline -This pipeline is responsible for scratch-building dist-git pull requests. - -It creates an SRPM and sends it to Koji where the actual magic happens. +This pipeline scratch-builds dist-git pull requests. diff --git a/pullRequest2scratchBuild.sh b/pullRequest2scratchBuild.sh deleted file mode 100755 index 6bde9f0..0000000 --- a/pullRequest2scratchBuild.sh +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash - -# Scratch-build pull requests. And add enough metadata so it is later posible -# to map such scratch-builds back to pull requests. -# -# Note this is an ugly hack. The way the tracking works is by submitting a SRPM -# to Koji. The SRPM has a carefurly crafted name. The name is preserved by Koji -# and thus can be later "decoded" to get the information about the original -# pull request. -# -# SRPM naming schema: -# fedora-ci___;.f34.src.rpm -# Note "fork-repo-full-name" cannot contain URL unsafe characters, so all slashes -# are replaced with colons. I.e. "forks/user/rpms/repo" would be encoded as "forks:user:rpms:repo" -# in the SRPM name. - -# Required environment variables: -# REPO_FULL_NAME - full name of the repository; for example: "rpms/jenkins" -# REPO_NAME - short name of the repository; for example: "jenkins" -# RELEASE_ID - release id; for example: "f34" -# PR_ID - pull request number; for example: 2 -# PR_UID - Pagure's unique pull request id -# PR_COMMIT - commit hash -# PR_COMMENT - Pagure's comment id that triggered the testing, 0 if the pull request was just opened -# SOURCE_REPO_FULL_NAME - full name of the source repository; for example: "forks/user/rpms/repo" -# KOJI_KEYTAB - path to the keytab that can be used to build SRPMs in Koji -# KRB_PRINCIPAL - kerberos principal -# FEDPKG_OPTS - extra options to pass to the "fedpkg scratch-build" command - -workdir=${PWD} -fedpkg_bin=${FEDPKG_BIN:-/usr/bin/fedpkg} -pagure_url=${PAGURE_URL:-https://src.fedoraproject.org} -mock_config="${RELEASE_ID}-x86_64" - - -# Guess the mock config name from the release id -epel_pattern="epel[0-9]+$" -epel_next_pattern="epel[0-9]+-next$" -if [[ "${RELEASE_ID}" == "${RAWHIDE_RELEASE_ID}" ]]; then - # rawhide - mock_config="fedora-rawhide-x86_64" -elif [[ "${RELEASE_ID}" == f* ]]; then - mock_config="fedora-${RELEASE_ID:1}-x86_64" -elif [[ "${RELEASE_ID}" == epel7 ]]; then - # just EPEL 7, there is no CentOS Stream 7 - mock_config="centos+epel-7-x86_64" -elif [[ "${RELEASE_ID}" =~ $epel_pattern ]]; then - # EPEL 8+ - mock_config="centos-stream+epel-${RELEASE_ID:4}-x86_64" -elif [[ "${RELEASE_ID}" =~ $epel_next_pattern ]]; then - # EPEL 8+ Next - mock_config="centos-stream+epel-next-${RELEASE_ID:4:1}-x86_64" -fi - -fedpkg_log_file="${workdir}/fedpkg.log" -koji_url_file="${workdir}/koji_url" -task_id_file="${workdir}/task_id" - -set -e -set -x - -rm -f "${fedpkg_log_file}" -rm -f "${koji_url_file}" -rm -f "${task_id_file}" - -function cleanup() { - # Remove directory, if it exists already - local dir_name=${1} - if [ -d "${dir_name}" ]; then - rm -Rf ${dir_name} - fi -} - - -function prepare_repository() { - # Clone the repository and fetch the pull request changes - local repo_full_name=${1} - local pr_id=${2} - local repo_name=$(basename ${repo_full_name}) - - ${fedpkg_bin} clone -a ${repo_name} - pushd ${repo_name} - git fetch ${pagure_url}/${repo_full_name}.git refs/pull/${pr_id}/head:pr${pr_id} - git checkout pr${pr_id} - popd -} - -cleanup ${REPO_NAME} -prepare_repository ${REPO_FULL_NAME} ${PR_ID} -cd ${REPO_NAME} - -# Build SRPM -fedpkg sources -mock --isolation=simple --verbose -r "${mock_config}" --resultdir=./ --buildsrpm --spec *.spec --source . -srpm_path=$(ls -1 | grep ".src.rpm$" | awk '{ print $1 }') -srpm_name=$(basename ${srpm_path}) -new_srpm_name="fedora-ci_${PR_UID}_${PR_COMMIT}_${PR_COMMENT};${SOURCE_REPO_FULL_NAME//\//:}.${RELEASE_ID}.src.rpm" -mv ${srpm_name} ${new_srpm_name} - -# Scratch-build the SRPM in Koji -kinit -k -t ${KOJI_KEYTAB} ${KRB_PRINCIPAL} - -${fedpkg_bin} scratch-build --nowait --fail-fast ${FEDPKG_OPTS} --target ${RELEASE_ID} --srpm ${new_srpm_name} | tee "${fedpkg_log_file}" - -cat "${fedpkg_log_file}" | grep '^Task info: ' | awk '{ print $3 }' | tee "${koji_url_file}" - -cat "${fedpkg_log_file}" | grep '^Created task: ' | awk '{ print $3 }' | tee "${task_id_file}" diff --git a/scratch-build.sh b/scratch-build.sh new file mode 100755 index 0000000..7501a16 --- /dev/null +++ b/scratch-build.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Scratch-build pull requests in Koji. + +# Required environment variables: +# KOJI_KEYTAB - path to the keytab that can be used to build packages in Koji +# KRB_PRINCIPAL - kerberos principal + +workdir=${PWD} + +if [ $# -ne 3 ]; then + echo "Usage: $0 " + exit 101 +fi + +koji_log=${workdir}/koji.log +koji_url=${workdir}/koji_url +task_id_file=${workdir}/task_id + +set -e +set -x + +rm -f ${koji_log} +rm -f ${koji_url} +rm -f ${task_id_file} + +profile=${1} +target=${2} +source_url=${3} + +if [ -z "${KOJI_KEYTAB}" ]; then + echo "Missing keytab, cannot continue..." + exit 101 +fi + +if [ -z "${KRB_PRINCIPAL}" ]; then + echo "Missing kerberos principal, cannot continue..." + exit 101 +fi + +kinit -k -t ${KOJI_KEYTAB} ${KRB_PRINCIPAL} + +koji -p ${profile} build --scratch --fail-fast --nowait ${target} ${source_url} > ${koji_log} +cat ${koji_log} + +cat ${koji_log} | grep '^Task info: ' | awk '{ print $3 }' > ${koji_url} + +task_id=$(cat ${koji_log} | grep '^Created task: ' | awk '{ print $3 }' | tee ${task_id_file})