CI for mesa in Fedora Project

Today I played with jenkins for my primary work. I wanted to check sources periodically and if it has been changed – build new RPM package from new git version. I have started playing with mesa, because I maintain it in Fedora and has git version in Rawhide which I’m building from time to time from git.

Q: What it’s doing right now?
A: Checking if there new upstream commits, updating .spec file, commiting to fedorapeople git repository, copying .src.rpm to fedorapeople http site and submitting to build in COPR repo.

Q: How I can use this CI and what version of Fedora I need?
A: You can use this CI only on Fedora Rawhide. You can enable repo via # dnf copr enable ignatenkobrain/mesa and update packages.

How I built this in jenkins?

First, I installed jenkins via # dnf install jenkins, started it via # systemctl start jenkins and opened browser at http://localhost:8080/.
Installed some plugins: Git Plugin and Multiple SCMs Plugin.
Uploaded my .fedora.cert and .fedora-server-ca.cert to /var/lib/jenkins/ directory.
Created COPR config in /var/lib/jenkins/.config/copr as described in API page.
Added credential in jenkins with private ssh key which can push to fedorapeople git repository (the same as in FAS).
Created job in jenkins with name mesa and configured it:

  1. Source Code Management -> Multiple SCMs
  2. Add SCM -> Git
    1. Repository URL -> ssh://
    2. Credentials -> ignatenkobrain (Fedora Project)
    3. Advanced
    4. Name -> fedora
    5. Add -> Check out to a sub-directory
    6. Local subdirectory for repo -> fedora
    7. Add -> Custom user name/email address
    8. -> Igor Gnatenko
    9. ->
    10. Add -> Wipe out repository & force clone
  3. Add SCM -> Git
    1. Repository URL -> git://
    2. Advanced
    3. Name -> upstream
    4. Add -> Check out to a sub-directory
    5. Local subdirectory for repo -> upstream
  4. Poll SCM -> H * * * *
  5. Add build step -> Exexute shell
    1. Command ->
          python - << EOF
      import rpm
      import re
      sp = rpm.spec("mesa.spec")
      print(re.sub(r"\.fc.*$", "", sp.sourceHeader.EVR))
      cd fedora/
      git checkout master
      REV=`GIT_DIR=../upstream/.git git rev-parse --short HEAD`
      sed -i \
          -e "s/^\(%define githash \).*/\1${REV}/g" \
      ret=$(EVR=`get_evr` python - << EOF
      import requests
      import os
      r = requests.get("").json()
      for x in r["builds"]:
          if os.environ["EVR"] in x['src_pkg'] and x['state'] != "failed":
              print("Already built")
      [[ "${ret}" == *"Already built"* ]] && exit 0
      rm -f ${DIRNAME}.tar.xz
      GIT_DIR=../upstream/.git git archive --format=tar --prefix=${DIRNAME}/ HEAD | xz > ${DIRNAME}.tar.xz
      rm -rf ${DIRNAME}
      ./ ${DIRNAME}.tar.xz
      rm -rf ${DIRNAME}
      sed -i \
          -e "s/^\(Release:\).*/\1 0.devel.${BUILD_NUMBER}.%{git}%{?dist}/g" \
      CHLOG=`date "+%a %b %d %Y Igor Gnatenko <> - ${EVR}"`
      sed -i \
          -e "s/^\(%changelog\)/\1\n* ${CHLOG}\n- ${REV}\n/g" \
      fedpkg new-sources ${DIRNAME}.tar.xz
      git commit -a -s -m "${REV}"
      git push fedora master
      mkdir -p SRPMS/
      SRPM=`rpmbuild -bs -D "_sourcedir ${WORKSPACE}/fedora" -D "_srcrpmdir ${WORKSPACE}/fedora/SRPMS/" mesa.spec`
      SRPM=`basename $(echo ${SRPM##Wrote: })`
      scp ${WORKSPACE}/fedora/SRPMS/${SRPM}
      copr-cli build mesa${SRPM}

Probably I could do this more easy. If so – let me know 😉