Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Build rpm with Jenkins project

Here is how I build rpm files in Jenkins.

Prerequisites

Add a Fedora node to the cluster. I am running Jenkins on Devuan, which obviously is not ideal for building rpms. I added a few labels, which are space-delimited which I found unusual. But whatever. I used a service account, and set up an ssh key for passwordless authentication. Configuring a Jenkins
node, with name fc30x-01a and a remote directory and ssh
setup. Add a user and grant them some specific sudo permissions:

useradd jenkins

cat <<EOF >/etc/sudoers.d/70_jenkins
User_Alias JENKINS = jenkins
Defaults:JENKINS !requiretty
JENKINS fc30x-01a=(root)    NOPASSWD: /usr/bin/dnf -y builddep *
EOF

Install some build tools:

sudo dnf -y install rpm-build rpmdevtools

My rpmbuild workflow in Jenkins

Add a new project. Restrict it to run on label "fedora." Project
configuration showing restrict where project is run, to label
"fedora" Like last time, I am checking out my git repo to a local subdirectory. Screenshot of project configuration showing SCM, and
additional behavior of "Check out to a sub-
directory" All the build steps for this project are shell commands. The first command uses some tooling I learned about for this project: spectool. The dnf installs the build dependencies, and spectool downloads all the source files that are not already present in the directory.

pwd ; ls -altr ; mkdir -p rpmbuild ; cd rpmbuild ;
cp -p ../work/veracrypt/* . || :;
sudo dnf -y builddep *.spec ;
spectool -g *.spec ;

The actual build command happens in the second step. I am using a few macro definitions to keep everything happening in the present working directory.

cd rpmbuild ; rpmbuild --define "_topdir %(pwd)" --define "_builddir %{_topdir}" --define "_rpmdir %{_topdir}" --define "_sourcedir %{_topdir}" --define "_srcrpmdir %{_topdir}" --define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm" -ba *.spec

And the final step deploys the files to my nfs share for manual curation.

mkdir -p /mnt/public/Public/${JOB_NAME} ;
cp -p *.rpm */*.rpm /mnt/public/Public/${JOB_NAME}/ || :

References

Weblinks

  1. fedora - Automatically install build dependencies prior to building an RPM package - Stack Overflow
  2. rpm - How do I get rpmbuild to download all of the sources for a particular .spec? - Stack Overflow
  3. Rpmdevtools - Fedora Project Wiki
  4. Build RPMs using Jenkins/Hudson

Comments