<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Knowledge Base (Posts about jenkins)</title><link>https://bgstack15.ddns.net/blog/</link><description></description><atom:link href="https://bgstack15.ddns.net/blog/categories/jenkins.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2022 &lt;a href="mailto:bgstack15@gmail.com"&gt;bgstack15&lt;/a&gt; 
&lt;a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/"&gt;
&lt;img alt="Creative Commons License BY-SA"
style="border-width:0; margin-bottom:12px;"
src="https://bgstack15.ddns.net/.images/l_by-sa_4.0_88x31.png"&gt;&lt;/a&gt;</copyright><lastBuildDate>Sun, 27 Feb 2022 04:04:47 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Build rpm with Jenkins project</title><link>https://bgstack15.ddns.net/blog/posts/2020/02/04/build-rpm-with-jenkins-project/</link><dc:creator>bgstack15</dc:creator><description>&lt;p&gt;Here is how I build rpm files in Jenkins.&lt;/p&gt;
&lt;h2&gt;Prerequisites&lt;/h2&gt;
&lt;p&gt;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. &lt;img alt="Configuring a Jenkins
node, with name fc30x-01a and a remote directory and ssh
setup." src="https://bgstack15.ddns.net/blog/2020/01/node-settings-fc30x-01a.png"&gt; Add a user and grant them some specific sudo permissions:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;useradd jenkins

cat &amp;lt;&amp;lt;EOF &amp;gt;/etc/sudoers.d/70_jenkins
User_Alias JENKINS = jenkins
Defaults:JENKINS !requiretty
JENKINS fc30x-01a=(root)    NOPASSWD: /usr/bin/dnf -y builddep *
EOF
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Install some build tools:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt; &lt;span class="n"&gt;dnf&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;rpm&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;build&lt;/span&gt; &lt;span class="n"&gt;rpmdevtools&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;My rpmbuild workflow in Jenkins&lt;/h2&gt;
&lt;p&gt;Add a new project. Restrict it to run on label "fedora." &lt;img alt='Project
configuration showing restrict where project is run, to label
"fedora"' src="https://bgstack15.ddns.net/blog/2020/01/restrict-to-fedora.png"&gt; Like last time, I am checking out my git repo to a local
subdirectory. &lt;img alt='Screenshot of project configuration showing SCM, and
additional behavior of "Check out to a sub-
directory"' src="https://bgstack15.ddns.net/blog/2020/01/scm-save-to-subdir.png"&gt; 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.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;pwd&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;ls&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;altr&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;mkdir&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="n"&gt;rpmbuild&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;cd&lt;/span&gt; &lt;span class="n"&gt;rpmbuild&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;cp&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;../&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;veracrypt&lt;/span&gt;&lt;span class="o"&gt;/*&lt;/span&gt; &lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;:;&lt;/span&gt;
&lt;span class="n"&gt;sudo&lt;/span&gt; &lt;span class="n"&gt;dnf&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="n"&gt;builddep&lt;/span&gt; &lt;span class="o"&gt;*.&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;spectool&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;*.&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;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.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;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
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And the final step deploys the files to my nfs share for manual curation.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;mkdir -p /mnt/public/Public/&lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;JOB_NAME&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt; ;
cp -p *.rpm */*.rpm /mnt/public/Public/&lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;JOB_NAME&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;/ || :
&lt;/code&gt;&lt;/pre&gt;

&lt;h2&gt;References&lt;/h2&gt;
&lt;h3&gt;Weblinks&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/13227162/automatically-install-build-dependencies-prior-to-building-an-rpm-package"&gt;fedora - Automatically install build dependencies prior to building an RPM package - Stack Overflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/questions/33177450/how-do-i-get-rpmbuild-to-download-all-of-the-sources-for-a-particular-spec#33177482"&gt;rpm - How do I get rpmbuild to download all of the sources for a particular .spec? - Stack Overflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://fedoraproject.org/wiki/Rpmdevtools"&gt;Rpmdevtools - Fedora Project Wiki&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.mornati.net/build-rpms-using-jenkinshudson/"&gt;Build RPMs using Jenkins/Hudson&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</description><category>devops</category><category>fedora</category><category>jenkins</category><category>rpm</category><guid>https://bgstack15.ddns.net/blog/posts/2020/02/04/build-rpm-with-jenkins-project/</guid><pubDate>Tue, 04 Feb 2020 13:34:21 GMT</pubDate></item><item><title>Build dpkg with Jenkins project</title><link>https://bgstack15.ddns.net/blog/posts/2020/01/31/build-dpkg-with-jenkins-project/</link><dc:creator>bgstack15</dc:creator><description>&lt;p&gt;Here is how I build dpkgs in Jenkins. I have not yet tried the jenkinsfile
syntax, but I'm sure that's a better way to do it.&lt;/p&gt;
&lt;h2&gt;Prerequisites&lt;/h2&gt;
&lt;p&gt;Install the &lt;a href="https://plugins.jenkins.io/debian-package-builder"&gt;Debian Package Builder&lt;/a&gt; plugin. It adds a nice option for a build step which
simplifies the debuild process. Now, I use a &lt;a href="https://gitlab.com/bgstack15/stackrpms/"&gt;single
repository&lt;/a&gt; to store my rpm specs and
dpkg debian/ directories. It's not ideal, I realize, but it was based on the
architecture I understood at the time, as well as it was modeled after a few
upstream places I &lt;del&gt;rip off&lt;/del&gt;
&lt;a href="https://github.com/PhantomX/chinforpms"&gt;follow&lt;/a&gt;. So I had to set up the
Gitlab plugins:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://plugins.jenkins.io/gitlab-api"&gt;Gitlab API Plugin&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://plugins.jenkins.io/gitlab-plugin"&gt;GitLab Plugin&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;My debuild workflow in Jenkins&lt;/h2&gt;
&lt;p&gt;Make a new item, of type Freestyle project. &lt;img alt='screenshot of Jenkins wui where
the user is about to make a new project named
"veracrypt."' src="https://bgstack15.ddns.net/blog/2020/01/jenkins-new-project.png"&gt; To load my repository with its specs and debian/ directories, I
pointed to my public gitlab repo which is configured elsewhere in Jenkins.
&lt;img alt="Screenshot of jenkins project showing General settings, Gitlab
connection" src="https://bgstack15.ddns.net/blog/2020/01/use-gitlab-connection.png"&gt; I am pulling down the updates branch, of my main git repo, and
saving to a local subdirectory. &lt;img alt='Screenshot of project configuration showing
SCM, and additional behavior of "Check out to a sub-
directory"' src="https://bgstack15.ddns.net/blog/2020/01/scm-save-to-subdir.png"&gt; I'm behind a NAT, so I don't expect to easily set up a webhook.
But I really wish I would bother to get it hooked up so any repo changes would
do this. I'll have to check that out in the future. For the build steps, I
have some shell running before and after the main "Build debian package"
section. &lt;img alt="Screenshot of build steps from jenkins project, showing parts of
the shell statments and Build debian package
step." src="https://bgstack15.ddns.net/blog/2020/01/build-steps.png"&gt; I had to
&lt;a href="https://gitlab.com/bgstack15/stackrpms/commit/23612e0be6f210be3f96bc597f7a5d003b190f53"&gt;revamp&lt;/a&gt;
the debian/watch file in my veracrypt sources, because I wasn't smart enough
to get it to reliably download from sourceforge (oh how the might have
fallen). But
&lt;a href="https://manpages.debian.org/stretch/devscripts/uscan.1.en.html"&gt;uscan&lt;/a&gt; is a
wonderful tool that downloads the source tarball for a package. My first full
shell step:&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;uscan&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;ddd&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;destdir&lt;/span&gt; &lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;symlink&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;veracrypt&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;mkdir&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="n"&gt;dpkg&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;tar&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;zx&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;C&lt;/span&gt; &lt;span class="n"&gt;dpkg&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;strip&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;components&lt;/span&gt; &lt;span class="mh"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;find&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;maxdepth&lt;/span&gt; &lt;span class="mh"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;iregex&lt;/span&gt; &lt;span class="p"&gt;'.&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;\/veracrypt_[0-9]+.*orig.*tar.*z.?'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;head&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;n1&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;cp&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pr&lt;/span&gt; &lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;veracrypt&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;debian&lt;/span&gt; &lt;span class="n"&gt;dpkg&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The syntax got a little weird when I was switching between the bzip2 and the
gzip file. Also, I don't always know the filename, ergo the find command. And
then, the Build debian package step. The source tarball was extracted to the
dpkg/ location, and the debian dir copied there. I really appreciate the
ability to specify where the debian/ directory is. And the final shell step
deploys the files to my nfs share for final processing by hand. I hand-curate
what's in my own repo. I don't have a proper pool/ setup like the real Devuan
repos, so I curate it myself, plus my volume is low enough I can do it all
myself.&lt;/p&gt;
&lt;pre class="code literal-block"&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;mkdir -p /mnt/public/Public/&lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;JOB_NAME&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt; ;
cp -p *.build *.buildinfo *.changes *.deb *.debian.tar* *.dsc /mnt/public/Public/&lt;span class="cp"&gt;${&lt;/span&gt;&lt;span class="n"&gt;JOB_NAME&lt;/span&gt;&lt;span class="cp"&gt;}&lt;/span&gt;/
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And that's it! For now I will trigger these builds manually.&lt;/p&gt;</description><category>devops</category><category>devuan</category><category>dpkg</category><category>jenkins</category><guid>https://bgstack15.ddns.net/blog/posts/2020/01/31/build-dpkg-with-jenkins-project/</guid><pubDate>Fri, 31 Jan 2020 13:31:02 GMT</pubDate></item></channel></rss>