<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Jenkins | A DevOps Blog</title><link>https://blog.bsdserver.nl/tag/jenkins/</link><description>Hands-on DevOps and homelab content: Kubernetes clusters, self-hosted services, CI/CD pipelines and infrastructure as code, by Patrick de Ruiter of We Build Your Cloud.</description><language>en</language><image><url>https://blog.bsdserver.nl/images/app-icon.svg</url><title>A DevOps Blog</title><link>https://blog.bsdserver.nl/</link></image><lastBuildDate>Wed, 18 Nov 2026 09:00:00 +0100</lastBuildDate><atom:link href="https://blog.bsdserver.nl/tag/jenkins/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title>Bitbucket Self-Hosted Runners: Bridging the Gap to Internal Jenkins</title><link>https://blog.bsdserver.nl/bitbucket-self-hosted-runners-bridging-the-gap-to-internal-jenkins/</link><guid isPermaLink="false">69809da0e0422600018c02ab</guid><dc:creator>Patrick de Ruiter</dc:creator><pubDate>Mon, 02 Feb 2026 12:52:38 +0000</pubDate><description>Preface: If you're running Jenkins in an internal datacenter and using Bitbucket Cloud for source control, you've likely hit this wall: Bitbucket can't…</description><category>DevOps</category><category>CI/CD</category><category>Bitbucket</category><category>Jenkins</category><category>Docker</category><media:content url="https://blog.bsdserver.nl/content/images/2026/02/bb-sh-runner-jenkins.png" medium="image"/><content:encoded><![CDATA[<p>If you&rsquo;re running Jenkins in an internal datacenter and using Bitbucket Cloud for source control, you&rsquo;ve likely hit this wall: Bitbucket can&rsquo;t send webhooks to Jenkins because your Jenkins server isn&rsquo;t publicly accessible. The typical workaround is having Jenkins poll every repository for changes, which is slow and resource-intensive.</p>
<p>This post flips the connection. A Bitbucket self-hosted runner inside your network picks up a pipeline step on every push and calls Jenkins with a webhook, so builds start immediately and Jenkins stays internal.</p>
<h2 id="why-a-self-hosted-runner">Why a Self-Hosted Runner? <a class="anchor" data-pagefind-ignore href="#why-a-self-hosted-runner" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>No inbound firewall rules</strong> - The runner connects <em>out</em> to Bitbucket Cloud over HTTPS to fetch jobs.</li>
<li><strong>Near-instant triggers</strong> - Jenkins builds start on push, not at the next poll.</li>
<li><strong>Less load</strong> - No polling of dozens of repositories.</li>
<li><strong>Jenkins stays internal</strong> - Only the runner, inside your network, talks to it.</li>
</ul>
<table>
	<thead>
			<tr>
					<th>Approach</th>
					<th>How Jenkins learns about a push</th>
					<th>Trade-off</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Polling</td>
					<td>Jenkins asks every repository periodically</td>
					<td>Slow, wasteful</td>
			</tr>
			<tr>
					<td>Inbound webhook</td>
					<td>Bitbucket calls Jenkins directly</td>
					<td>Jenkins must be reachable from the internet</td>
			</tr>
			<tr>
					<td>Self-hosted runner</td>
					<td>Runner inside the network calls Jenkins</td>
					<td>One extra host and container to run</td>
			</tr>
	</tbody>
</table>
<h3 id="when-to-use-it">When to use it <a class="anchor" data-pagefind-ignore href="#when-to-use-it" aria-label="Link to this section">#</a></h3>
<ul>
<li><strong>Use it</strong> when Jenkins cannot be exposed to the internet and you want push-triggered builds from Bitbucket Cloud.</li>
<li><strong>Skip it</strong> if Jenkins is already reachable for webhooks, or if you can move the builds into Bitbucket Pipelines altogether.</li>
</ul>
<h2 id="how-it-works">How It Works <a class="anchor" data-pagefind-ignore href="#how-it-works" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Component</th>
					<th>Runs on</th>
					<th>Job</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Bitbucket Pipelines</td>
					<td>Bitbucket Cloud</td>
					<td>Starts a pipeline on push and assigns the step to your runner by its labels.</td>
			</tr>
			<tr>
					<td>Self-hosted runner</td>
					<td>Docker host in your network</td>
					<td>Fetches the step from Bitbucket and runs it.</td>
			</tr>
			<tr>
					<td>Generic Webhook Trigger</td>
					<td>Jenkins</td>
					<td>Receives the <code>curl</code> call and starts the matching job.</td>
			</tr>
	</tbody>
</table>
<p>The flow: developer pushes → Bitbucket Pipeline triggers, targeting your runner → runner (inside your network) runs a <code>curl</code> to Jenkins → Jenkins starts the build.</p>
<h2 id="setting-up-the-runner">Setting Up the Runner <a class="anchor" data-pagefind-ignore href="#setting-up-the-runner" aria-label="Link to this section">#</a></h2>
<h3 id="prepare-your-host">Prepare Your Host <a class="anchor" data-pagefind-ignore href="#prepare-your-host" aria-label="Link to this section">#</a></h3>
<p>The runner needs a Linux server with Docker: 8GB RAM minimum, and outbound HTTPS access to Bitbucket&rsquo;s services.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Install Docker (Ubuntu/Debian)</span>
</span></span><span class="line"><span class="cl">sudo apt-get update <span class="o">&amp;&amp;</span> sudo apt-get install -y docker.io
</span></span><span class="line"><span class="cl">sudo systemctl <span class="nb">enable</span> --now docker
</span></span></code></pre></div><p>Disable swap to avoid unpredictable build behavior. Atlassian recommends turning swap off and setting <code>vm.swappiness</code> to 1, persistently:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo swapoff -av
</span></span><span class="line"><span class="cl">sudo sed -i <span class="s1">&#39;/\sswap\s/s/^/#/&#39;</span> /etc/fstab
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;vm.swappiness = 1&#39;</span> <span class="p">|</span> sudo tee -a /etc/sysctl.conf
</span></span><span class="line"><span class="cl">sudo sysctl -p
</span></span></code></pre></div><h3 id="register-with-bitbucket">Register with Bitbucket <a class="anchor" data-pagefind-ignore href="#register-with-bitbucket" aria-label="Link to this section">#</a></h3>
<p>Registration creates the runner&rsquo;s identity and credentials in your workspace.</p>
<ol>
<li>In your workspace settings, open <strong>Workspace runners</strong> under Pipelines.</li>
<li>Click <strong>Add runner</strong> and select <strong>Linux Docker</strong>.</li>
<li>Name it, for example <code>internal-jenkins-trigger</code>, and add a custom label (we&rsquo;ll use <code>internal</code>). Pipelines use the label to pick this runner.</li>
</ol>
<p>Bitbucket generates a Docker command with your credentials. Run it:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">docker run -d <span class="se">\
</span></span></span><span class="line"><span class="cl">  --name bitbucket-runner <span class="se">\
</span></span></span><span class="line"><span class="cl">  --restart<span class="o">=</span>unless-stopped <span class="se">\
</span></span></span><span class="line"><span class="cl">  -v /tmp:/tmp <span class="se">\
</span></span></span><span class="line"><span class="cl">  -v /var/run/docker.sock:/var/run/docker.sock <span class="se">\
</span></span></span><span class="line"><span class="cl">  -e <span class="nv">ACCOUNT_UUID</span><span class="o">={</span>your-uuid<span class="o">}</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  -e <span class="nv">RUNNER_UUID</span><span class="o">={</span>your-runner-uuid<span class="o">}</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  -e <span class="nv">OAUTH_CLIENT_ID</span><span class="o">={</span>client-id<span class="o">}</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  -e <span class="nv">OAUTH_CLIENT_SECRET</span><span class="o">={</span>client-secret<span class="o">}</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">  -e <span class="nv">WORKING_DIRECTORY</span><span class="o">=</span>/tmp <span class="se">\
</span></span></span><span class="line"><span class="cl">  docker-public.packages.atlassian.com/sox/atlassian/bitbucket-pipelines-runner:7
</span></span></code></pre></div><ul>
<li><code>--restart=unless-stopped</code>: the runner comes back after a reboot or crash.</li>
<li><code>/var/run/docker.sock</code>: the runner starts each pipeline step as its own container on this host.</li>
<li><code>ACCOUNT_UUID</code>, <code>RUNNER_UUID</code>, <code>OAUTH_*</code>: the runner&rsquo;s identity. Treat the client secret like a password.</li>
<li>Image tag: use the one from the command Bitbucket generates for you. The old <code>:1</code> tag still resolves, but it is frozen on a May 2024 build of the runner.</li>
</ul>
<p>Your runner will appear as &ldquo;Online&rdquo; in Bitbucket within seconds.</p>
<h2 id="configuring-jenkins">Configuring Jenkins <a class="anchor" data-pagefind-ignore href="#configuring-jenkins" aria-label="Link to this section">#</a></h2>
<p>Jenkins needs an endpoint the runner can call. The <strong>Generic Webhook Trigger</strong> plugin provides one and extracts values from a JSON payload.</p>
<p>Install it from <strong>Manage Jenkins &gt; Plugins</strong>, then configure your job:</p>
<ol>
<li>Enable &ldquo;Generic Webhook Trigger&rdquo; under Build Triggers</li>
<li>Set a token (e.g., <code>my-project-trigger-abc123</code>). The token selects which job is triggered.</li>
<li>Add variables to extract from the payload:
<ul>
<li><code>REPO</code> from <code>$.repository</code></li>
<li><code>BRANCH</code> from <code>$.branch</code></li>
<li><code>COMMIT</code> from <code>$.commit</code></li>
</ul>
</li>
</ol>
<p>Your webhook URL becomes:</p>
<pre tabindex="0"><code>http://jenkins-server:8080/generic-webhook-trigger/invoke?token=my-project-trigger-abc123
</code></pre><h2 id="the-pipeline">The Pipeline <a class="anchor" data-pagefind-ignore href="#the-pipeline" aria-label="Link to this section">#</a></h2>
<p>The <code>bitbucket-pipelines.yml</code> in your repository ties it together: one step, on your runner, that calls Jenkins.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">atlassian/default-image:4</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">pipelines</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">default</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span>- <span class="nt">step</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">Trigger Jenkins</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">runs-on</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span>- <span class="l">self.hosted</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span>- <span class="l">linux</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span>- <span class="l">internal</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">script</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span>- <span class="p">|</span><span class="sd">
</span></span></span><span class="line"><span class="cl"><span class="sd">            curl -X POST \
</span></span></span><span class="line"><span class="cl"><span class="sd">              -H &#34;Content-Type: application/json&#34; \
</span></span></span><span class="line"><span class="cl"><span class="sd">              -d &#39;{
</span></span></span><span class="line"><span class="cl"><span class="sd">                &#34;repository&#34;: &#34;&#39;&#34;$BITBUCKET_REPO_SLUG&#34;&#39;&#34;,
</span></span></span><span class="line"><span class="cl"><span class="sd">                &#34;branch&#34;: &#34;&#39;&#34;$BITBUCKET_BRANCH&#34;&#39;&#34;,
</span></span></span><span class="line"><span class="cl"><span class="sd">                &#34;commit&#34;: &#34;&#39;&#34;$BITBUCKET_COMMIT&#34;&#39;&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">              }&#39; \
</span></span></span><span class="line"><span class="cl"><span class="sd">              &#34;$JENKINS_WEBHOOK_URL&#34;</span><span class="w">
</span></span></span></code></pre></div><ul>
<li><code>default</code>: runs on every push to any branch.</li>
<li><code>runs-on</code>: <code>self.hosted</code> and <code>linux</code> send the step to a self-hosted Linux runner; <code>internal</code> picks yours. Without <code>runs-on</code> the step runs in Bitbucket Cloud, which cannot reach Jenkins.</li>
<li>The payload: the built-in <code>BITBUCKET_*</code> variables, matching the variables configured in Jenkins.</li>
</ul>
<p>Store <code>JENKINS_WEBHOOK_URL</code> as a <strong>secured repository variable</strong> in Bitbucket. This keeps your token out of logs and version control.</p>
<h2 id="a-more-robust-version">A More Robust Version <a class="anchor" data-pagefind-ignore href="#a-more-robust-version" aria-label="Link to this section">#</a></h2>
<p>The plain <code>curl</code> succeeds even when Jenkins answers with an error. For production, check the HTTP status and fail the step otherwise:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">script</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="p">|</span><span class="sd">
</span></span></span><span class="line"><span class="cl"><span class="sd">    response=$(curl -s -w &#34;%{http_code}&#34; -o /tmp/response.txt \
</span></span></span><span class="line"><span class="cl"><span class="sd">      -X POST \
</span></span></span><span class="line"><span class="cl"><span class="sd">      -H &#34;Content-Type: application/json&#34; \
</span></span></span><span class="line"><span class="cl"><span class="sd">      -d &#39;{&#34;repository&#34;: &#34;&#39;&#34;$BITBUCKET_REPO_SLUG&#34;&#39;&#34;, &#34;branch&#34;: &#34;&#39;&#34;$BITBUCKET_BRANCH&#34;&#39;&#34;, &#34;commit&#34;: &#34;&#39;&#34;$BITBUCKET_COMMIT&#34;&#39;&#34;}&#39; \
</span></span></span><span class="line"><span class="cl"><span class="sd">      &#34;$JENKINS_WEBHOOK_URL&#34;)
</span></span></span><span class="line"><span class="cl"><span class="sd">    
</span></span></span><span class="line"><span class="cl"><span class="sd">    if [ &#34;$response&#34; -ge 200 ] &amp;&amp; [ &#34;$response&#34; -lt 300 ]; then
</span></span></span><span class="line"><span class="cl"><span class="sd">      echo &#34;Jenkins triggered successfully&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">    else
</span></span></span><span class="line"><span class="cl"><span class="sd">      echo &#34;Failed: HTTP $response&#34;
</span></span></span><span class="line"><span class="cl"><span class="sd">      cat /tmp/response.txt
</span></span></span><span class="line"><span class="cl"><span class="sd">      exit 1
</span></span></span><span class="line"><span class="cl"><span class="sd">    fi</span><span class="w">
</span></span></span></code></pre></div><h2 id="maintenance-tips">Maintenance Tips <a class="anchor" data-pagefind-ignore href="#maintenance-tips" aria-label="Link to this section">#</a></h2>
<p>Runners accumulate images over time. Clean up Docker regularly:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Cron job for daily cleanup at 3 AM</span>
</span></span><span class="line"><span class="cl"><span class="m">0</span> <span class="m">3</span> * * * docker system prune -af --volumes
</span></span></code></pre></div><p>When a step does not start or the runner shows offline, check its log first:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">docker logs -f bitbucket-runner
</span></span></code></pre></div><h2 id="security-considerations">Security Considerations <a class="anchor" data-pagefind-ignore href="#security-considerations" aria-label="Link to this section">#</a></h2>
<ul>
<li>Store all tokens as secured variables, never in code</li>
<li>Create a dedicated Jenkins user with minimal permissions (just enough to trigger builds)</li>
<li>Use HTTPS for Jenkins if possible</li>
<li>Rotate tokens periodically</li>
</ul>
<h2 id="wrapping-up">Wrapping Up <a class="anchor" data-pagefind-ignore href="#wrapping-up" aria-label="Link to this section">#</a></h2>
<p>Using a self-hosted runner as a bridge gives you Bitbucket Cloud with Jenkins kept internal, and builds trigger instantly instead of waiting for the next poll cycle. The setup takes about 30 minutes.</p>
<p><em>Have questions or run into issues? Drop a comment below.</em></p>
]]></content:encoded></item></channel></rss>