<?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>Piecing things together (Posts about jenkins)</title><link>https://wjoel.com/</link><description></description><atom:link href="https://wjoel.com/categories/jenkins.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><lastBuildDate>Sun, 15 Oct 2023 18:25:37 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Creating Jenkins pipelines with Ansible, part 2</title><link>https://wjoel.com/posts/ansible-jenkins-pipeline-part-2.html</link><dc:creator>Joel Wilsson</dc:creator><description>&lt;div id="outline-container-orga6bcbf8" class="outline-2"&gt;
&lt;h2 id="orga6bcbf8"&gt;The job-dsl and Pipeline plugins&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-orga6bcbf8"&gt;
&lt;p&gt;
This is a continuation of the &lt;a href="https://wjoel.com/posts/ansible-jenkins-pipeline-part-1.html"&gt;previous post&lt;/a&gt;.
For each project there are only two things we want to do.
&lt;/p&gt;

&lt;ul class="org-ul"&gt;
&lt;li&gt;Check out the source code.&lt;/li&gt;
&lt;li&gt;Run the pipeline in the Jenkinsfile at the root of the repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
This can be accomplished with the job-dsl plugin. It takes a definition
of Jenkins jobs we want, and creates or updates them, as necessary.
Somewhat confusingly, job-dsl itself needs to be run from a Jenkins job,
known as a seed job.
&lt;/p&gt;

&lt;p&gt;
The &lt;b&gt;only&lt;/b&gt; reason for this job to exist is so that job-dsl can run,
and &lt;b&gt;every&lt;/b&gt; other job should be created with job-dsl. Yes, it is a bit
mind bending, but if you don't think of it as a job but as a script which
you run from Jenkins it gets easier.
&lt;/p&gt;

&lt;p&gt;
In our case, every other job will look the same. They'll all be Pipeline
jobs which run a Jenkinsfile after checking out a git repository from the
same git host.
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;{%&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;jenkins_git_repositories&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;%}&lt;/span&gt;
&lt;span class="n"&gt;pipelineJob&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'{{ repository }}'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;definition&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;cpsScm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="n"&gt;scm&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;git&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="n"&gt;remote&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'{{ jenkins_git_user }}@{{ jenkins_git_host }}:'&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;
&lt;span class="w"&gt;                &lt;/span&gt;&lt;span class="s1"&gt;'{{ jenkins_git_path }}/{{ repository }}.git'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;          &lt;/span&gt;&lt;span class="n"&gt;branch&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'master'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="n"&gt;scriptPath&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Jenkinsfile'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="w"&gt;  &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="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;endfor&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;%}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://wjoel.com/posts/ansible-jenkins-pipeline-part-2.html"&gt;Read more…&lt;/a&gt; (5 min remaining to read)&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</description><category>ansible</category><category>infrastructure</category><category>jenkins</category><guid>https://wjoel.com/posts/ansible-jenkins-pipeline-part-2.html</guid><pubDate>Wed, 10 Aug 2016 19:52:00 GMT</pubDate></item><item><title>Creating Jenkins pipelines with Ansible, part 1</title><link>https://wjoel.com/posts/ansible-jenkins-pipeline-part-1.html</link><dc:creator>Joel Wilsson</dc:creator><description>&lt;div id="outline-container-orgdc2700c" class="outline-2"&gt;
&lt;h2 id="orgdc2700c"&gt;Introduction&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-orgdc2700c"&gt;
&lt;p&gt;
Infrastructure as code, continuous integration (CI),
continuous delivery (CD), and version control
(also known as source control management, or SCM) are good things.
In this post and the next we'll automate the deployment of a
system to do CI/CD in what I consider a proper way, where the definition of
your build and deployment pipelines live alongside your code in
git repositories on some server you have SSH access to.
&lt;/p&gt;

&lt;p&gt;
We'll use &lt;a href="https://jenkins.io"&gt;Jenkins&lt;/a&gt; for CI/CD and &lt;a href="https://www.ansible.com/"&gt;Ansible&lt;/a&gt; to install it.
Jenkins has been around for more
than a decade, created before anyone had ever uttered the word "devops".
Since it's old, Jenkins has a lot of features, most of them provided as plugins.
The core itself isn't bad, and is stable and relatively free from bugs
because it has been in use by a lot of people for such a long time.
All those years
have created a graveyard of plugins, though, yet some plugins are essential if
you want to use Jenkins "properly". Want a timestamp for your builds? There's
a plugin for that. Actually, there's more than one plugin for that.
&lt;/p&gt;

&lt;p&gt;
Jenkins comes from a time when people thought it
was great to have easy to use web interfaces to configure their build systems.
The web interface gets in the
way of infrastructure as code, where configuration is version controlled
and changed by editing text files, not by clicking buttons.
&lt;/p&gt;

&lt;p&gt;
Pipeline is a "new" feature of Jenkins 2.0, but it is based on a plugin
which used to be known as Workflow. Using Pipeline we can describe
how to test, build and deploy our project using text. That description is
typically saved in a file named Jenkinsfile. We'll also use the job-dsl plugin
to create the Pipeline jobs, but everything else will be done with shell
scripts and kept as simple as possible.
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://wjoel.com/posts/ansible-jenkins-pipeline-part-1.html"&gt;Read more…&lt;/a&gt; (4 min remaining to read)&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</description><category>ansible</category><category>infrastructure</category><category>jenkins</category><guid>https://wjoel.com/posts/ansible-jenkins-pipeline-part-1.html</guid><pubDate>Sat, 06 Aug 2016 18:49:00 GMT</pubDate></item></channel></rss>