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:
- Source Code Management -> Multiple SCMs
- Add SCM -> Git
- Repository URL ->
ssh://ignatenkobrain@fedorapeople.org/home/fedora/ignatenkobrain/public_git/mesa.git
- Credentials ->
ignatenkobrain (Fedora Project)
- Advanced
- Name ->
fedora
- Add -> Check out to a sub-directory
- Local subdirectory for repo ->
fedora
- Add -> Custom user name/email address
- user.name ->
Igor Gnatenko
- user.email ->
ignatenkobrain@fedoraproject.org
- Add -> Wipe out repository & force clone
- Repository URL ->
- Add SCM -> Git
- Repository URL ->
git://anongit.freedesktop.org/mesa/mesa
- Advanced
- Name ->
upstream
- Add -> Check out to a sub-directory
- Local subdirectory for repo ->
upstream
- Repository URL ->
- Poll SCM ->
H * * * *
- Add build step -> Exexute shell
- Command ->
get_evr() { python - << EOF import rpm import re sp = rpm.spec("mesa.spec") print(re.sub(r"\.fc.*$", "", sp.sourceHeader.EVR)) EOF } cd fedora/ git checkout master REV=`GIT_DIR=../upstream/.git git rev-parse --short HEAD` sed -i \ -e "s/^\(%define githash \).*/\1${REV}/g" \ mesa.spec ret=$(EVR=`get_evr` python - << EOF import requests import os r = requests.get("https://copr.fedoraproject.org/api/coprs/ignatenkobrain/mesa/monitor/").json() for x in r["builds"]: if os.environ["EVR"] in x['src_pkg'] and x['state'] != "failed": print("Already built") EOF ) [[ "${ret}" == *"Already built"* ]] && exit 0 DIRNAME=mesa-${REV} rm -f ${DIRNAME}.tar.xz GIT_DIR=../upstream/.git git archive --format=tar --prefix=${DIRNAME}/ HEAD | xz > ${DIRNAME}.tar.xz rm -rf ${DIRNAME} ./sanitize-tarball.sh ${DIRNAME}.tar.xz rm -rf ${DIRNAME} sed -i \ -e "s/^\(Release:\).*/\1 0.devel.${BUILD_NUMBER}.%{git}%{?dist}/g" \ mesa.spec EVR=`get_evr` CHLOG=`date "+%a %b %d %Y Igor Gnatenko <ignatenkobrain@fedoraproject.org> - ${EVR}"` sed -i \ -e "s/^\(%changelog\)/\1\n* ${CHLOG}\n- ${REV}\n/g" \ mesa.spec 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} ignatenkobrain@fedorapeople.org:~/public_html/mesa-staging/ copr-cli build mesa https://ignatenkobrain.fedorapeople.org/mesa-staging/${SRPM}
- Command ->
Probably I could do this more easy. If so – let me know 😉