Install SalesforceDX CLI for Jenkins builds

Recently I’ve posted a story about Continuous Integration Setup based on SalesforceDX. There are few thighs that require detailed description. One of them is SalesforceDX Command Line Interface (CLI) installation process.

In this story, I want to share with you how to configure Jenkins specific plugin to install all required tools for SalesforceDX build that I presented in my last story.

Note: The configurations suitable and tested on Unix based machines (Linux Ubuntu 16.04 LTS and macOS Sierra 10.12.6). To configure the tools for Windows operation system you should change the scripts.

Custom Tools Plugin

In most cases companies have one distributed Jenkins environment where actual builds run on the slave machines.

Jenkins supports the “master/slave” mode, where the workload of building projects are delegated to multiple “slave” nodes, allowing a single Jenkins installation to host a large number of projects, or to provide different environments needed for builds/tests. — Jenkins Distributed builds

Custom Tools Plugin allows you to configure the script to prepare a tool before every Jenkins build. It means that common Jenkins user without administrator permissions can setup tools for their own build.

Even if you have raw Jenkins builds on the master machine, it is a good practice to use Custom Tools Plugin.

To install the plugin, navigate to Configure Jenkins > Manage Plugins menu:

There are should be tabs where one of them is Available. Navigate to the Available tab and search for “Custom Tools Plugin”. Then install the plugin.

In the story that I mentioned before, the build requires SalesforceDX CLI and jq utility. I will provide you the steps how to configure these specific tools.

SalesforceDX CLI installation settings

Navigate to Manage Jenkins > Global Tool Configuration:

In the Tools section, you can find the button Custom tools installation. Next press the button to open tools configuration section. It will show you the option to Add Custom Tool that you press on. There are you can manage the installer option. You should Add Installer to Run Shell Command. Also, delete the standard installer in case it was added by the plugin automatically.

Enter the Name as sfdx for CLI. The Command input field contains the script to install CLI. Here is the detail description about every command in this script:

1. curl "<url_for_sfdx_cli>" -o "sfdx.tar.xz"
2. mkdir sfdx
3. tar -xvJf sfdx.tar.xz >/dev/null 2>&1 -C sfdx --strip-components=1
  1. The command downloads the CLI binary using provided URL and saves it to the .tar.xz archive. The URL that you should use depends on your operating system. The official SalesforceDX documentation has the link to the manifest file where you can find your specific URL.
  2. Then the second command creates a sfdx directory for the CLI
  3. And the most advanced unarchives the downloaded tarball to the sfdx folder. Also, this command use specific parameter >/dev/null 2>$1. This parameter set tar command to be “silent”. So, the output generated by tar command is hidden to omit an unnecessary logging information. You should remove >/dev/null 2>$1 parameter in case you have a problem with CLI to see the error output.

And the last step to configure CLI you should provide the relative URL to the bin folder in the unarchived sfdx root. Custom Tools Plugin add this URL to the $PATH variable. Therefore you can use sfdx command from your builds.

JQ installation settings

Add Custom Tool again using the button described above and configure the installer to Run Shell Command like you did it for CLI:

Enter the Name as jq for the tool. Also, provide the script into the Command input field that will install the tool:

1. curl "<binary_jq_url>" -o "jq"
2. chmod -x jq
  1. The command downloads the binary jq file using provided URL and saves it as jq using -o "jq" parameter. The binary_jq_url you can find on the tool official website. There are different tool versions for certain operating system. On the moment of writing this story, the last version is 1.5. I use this version for all my builds.
  2. To run the tool you should make it executable. The second command does that for jq.

And the final piece is to enter the current directory ./ to the Tool Home input field. As I mentioned before, it will allow you to run jq from the Jenkins builds.

Adding tools to the build

To use the tools configured above, open a build Configure menu. There should be the checkbox Install custom tools in the Build Environment section. Select the checkbox and Add Tools to the build environment:


At this point, your build is independent of a Jenkins slave. It is not required to install the tools manually to a master or every slave. You are ready to use sfdx and jq in your builds.

If this article was useful for you, please sign it with an 👏 or share with your friends. It will force me to stay work on articles like that more, thanks!

Ruslan Kurchenko is an Advanced Salesforce Engineer from Kiev, Ukraine. He is passionate of Salesforce, JavaScript and Modern WEB Development. Connect with him on LinkedIn, Instagram or say Hi! on Twitter.