<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ dangerjs - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ dangerjs - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 27 Jun 2026 14:19:42 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/dangerjs/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to integrate DangerJS into GoCD pipelines ]]>
                </title>
                <description>
                    <![CDATA[ By Leonardo Lima At my current company, we have recently migrated our CI infra from CircleCI to GoCD. After a few months using the new CI platform, I was comfortable enough to juice it up. One of the things that I was planning was integrating DangerJ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-integrate-dangerjs-into-gocd-pipelines-7f930932ea07/</link>
                <guid isPermaLink="false">66c352e8bbe01f9810478693</guid>
                
                    <category>
                        <![CDATA[ Continuous Integration ]]>
                    </category>
                
                    <category>
                        <![CDATA[ dangerjs ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 01 Apr 2019 12:52:42 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*rOWdHY7akUNLQOGIh5VtoQ.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Leonardo Lima</p>
<p>At my current company, we have recently migrated our CI infra from CircleCI to <a target="_blank" href="https://www.gocd.org/">GoCD</a>. After a few months using the new CI platform, I was comfortable enough to juice it up. One of the things that I was planning was integrating <a target="_blank" href="http://danger.systems/js">DangerJS</a> — an amazing tool to expedite pull request reviews by performing configurable auto-checks on new code. What does it mean? No more time spent on writing PR comments like: “Oh, I believe you forgot X… Y… Z…”.</p>
<p>My goal with this article is to help the next person pursuing this mission to improve their team’s Code Quality and PR review processes.</p>
<h3 id="heading-context">Context</h3>
<p>I have used Danger’s powers before (though integrated with Ruby) and I already knew that the initial setup would be quite straightforward…if only we were still using CircleCI!</p>
<p>On my first attempt to integrate, I tried googling “Integrating DangerJS with GoCD” with no luck. Also, after reading DangerJS’ documentation, I’ve found that there was no such thing as a native-straightforward integration with GoCD that I could use.</p>
<p>That meant that I wouldn’t be able to easily integrate Danger’s checks into my CI flow. So I was left with a few options:</p>
<ol>
<li>Trying to make developers incorporate local manual runs of DangerJS commands;</li>
<li>Build a specific pipeline in (CircleCI/CodeShip/FooBar) to run just DangerJS;</li>
<li>Give up.</li>
</ol>
<p>I didn’t like either of my options, and I was really frustrated after a few hours spent in Danger and GoCD settings. Then I stumbled upon the “<a target="_blank" href="https://danger.systems/js/guides/the_dangerfile.html#using-danger-and-faking-being-on-a-ci">Using danger and fake being on a CI</a>” section in the DangerJS docs. That’s it! If I can fake being on a CI in my local machine, what’s the difference from faking a CI in a GoCD machine?</p>
<p>Afterwards, it was just a matter of figuring out how to emulate the same local behaviour inside GoCD’s infra.</p>
<h3 id="heading-first-steps">First steps</h3>
<p>Before anything, you have to go through the <a target="_blank" href="https://danger.systems/js/guides/getting_started.html#setting-up-danger-to-run-on-your-ci">official documentation</a> in order to set up and start using DangerJS.</p>
<p>Basically, what you need is to:</p>
<ul>
<li>Create your dangerfile.js file. There are a few <a target="_blank" href="https://danger.systems/js/guides/the_dangerfile.html#examples">examples here</a>.</li>
<li><a target="_blank" href="https://danger.systems/js/guides/getting_started.html#creating-a-bot-account-for-danger-to-use">Create a bot account</a> on GitHub/BitBucket for Danger to use</li>
<li>Open a PR with changed files to check your changes</li>
<li>Run DangerJS locally against a PR link (the one you’ve just opened)</li>
<li>Try to <a target="_blank" href="https://danger.systems/js/guides/the_dangerfile.html#using-danger-and-faking-being-on-a-ci">fake a CI environment</a> in your local machine</li>
</ul>
<p>In the next section, I’ll go deeper in this last step since it is the critical part to make DangerJS work with GoCD.</p>
<h3 id="heading-configuring-a-fake-ci-in-gocds-environment">Configuring a fake CI in GoCD’s environment</h3>
<p>First, if you still don’t have a detached GoCD pipeline to run only Pull Requests builds, I strongly recommend you to do so. <a target="_blank" href="https://docs.gocd.org/current/configuration/quick_pipeline_setup.html">Here is a guide</a> if you need some help setting that up.</p>
<p>Secondly, after creating your PR pipeline, create a new Job just for Danger:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/qmTP33WaR1bR5hpRzWag5D35amrOh5O6LmMW" alt="Image" width="632" height="634" loading="lazy"></p>
<p>Now, to be able to fake a CI using Danger, you need to set a bunch of environment variables such as:</p>
<pre><code><span class="hljs-keyword">export</span> DANGER_FAKE_CI=<span class="hljs-string">"YEP"</span>
<span class="hljs-keyword">export</span> DANGER_TEST_REPO=<span class="hljs-string">"username/reponame"</span>
</code></pre><p>In GoCD’s Pipeline Job settings, navigate to the Environment Variables tab and set those two env variables replacing the <strong>username/reponame</strong> placeholders with your own settings.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/iVqne-VCmoSnzmKOXDbZijdURv2QYyqmjwqQ" alt="Image" width="800" height="367" loading="lazy">
_I’d recommend placing the DANGER_GITHUB_API<em>TOKEN generated on the first DangerJS configuration steps in the Secure Variables section.</em></p>
<p>After this first batch of configurations, in order to actually run Danger’s tests in GoCD, you can use a shell script that executes the same commands used to fake a CI in a local environment. Let’s call this file danger-build.sh.</p>
<pre><code># danger-build.sh

echo <span class="hljs-string">'— — START DANGER JS VERIFICATION —'</span>

echo Testing against commits on PR: ${GO_SCM_PIPELINE_PR_URL}

DANGER_TEST_PR=${GO_SCM_PIPELINE_PR_ID} npx yarn danger ci

echo ‘ — — END OF DANGER JS VERIFICATION — — ‘
</code></pre><p>Please note that you’ll need node, npm/yarn previously installed in the GoCD available machine.</p>
<p><strong>Did you notice those two GO_SCM variables</strong>? They are the catch that let you run your Danger verifications inside a GoCD machine.</p>
<p>Please pay special attention to the PR_ID variable since it’s the one that provides the PR reference to let Danger read, interpret the changes, and then write suggestions in the Pull Request.</p>
<p>In case you’re curious, those environment variables were generated by GoCD’s machines. They can be assessed by running the <code>/usr/bin/printenv</code> UNIX command in a build and inspecting the output.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/TOzoSEn6HBEnOOVKEJZQTefZKKCd6rsQSMOt" alt="Image" width="800" height="415" loading="lazy"></p>
<p>And that’s it!</p>
<p>After mapping the proper env variables in your Shell script, the DangerJS verifications will start running in GoCD’s pipelines next to your current test suite.</p>
<p>To wrap up the steps:</p>
<ol>
<li><p>Setup the first DangerJS local files and settings</p>
</li>
<li><p>Create a specific Pipeline/Job in GoCD</p>
</li>
<li><p>Discover and then map the proper environment variables inside a shell script to let GoCD run DangerJS</p>
</li>
</ol>
<p>I hope that you’ve found the walkthrough helpful. If you have enjoyed the article please share with your fellow developers &amp; managers and help spread the word.</p>
<p>For any questions please feel free to ask in the comments section!</p>
<p>PS: Danger also has a lot of plugins options, <a target="_blank" href="https://danger.systems/js/">check them out</a>!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
