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. 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." Like last time, I am checking out my git repo to a local subdirectory. 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}/ || :
Comments