UiPath, Jenkins CICD Pipeline Tutorial - Part 1

In this tutorial, I teach you how to setup a basic UiPath CICD pipeline with Jenkins. This pipeline tracks a Github repository for changes and as soon as a new version of code is committed, it pushes a new build and to the UiPath orchestrator in an automated fashion.

Note: This tutorial is intended as a learning concept to get a pipeline up and running to explore CICD further. It is not intended as an approach for deploying code to production.

You can preview this implementation in the following video: UiPath, Jenkins CICD Pipeline - Part 1 - YouTube

Update: Part 2 is available here.

What you’ll need:

  • Admin rights to an orchestrator instance (UiPath Community or Enterprise Edition)
  • Jenkins installed on your Windows PC
  • A Github account and UiPath integrated with it

High level steps:

  1. Install Jenkins and UiPath Plugin
  2. Clone Github Repo
  3. Setup Jenkins Pipeline
  4. Connect Git Repository

In each stage I mention the pitfalls that you have to watch out for.

I have also included additional references at the end of this post. A special thanks to Satish Prasad - his post on RPABotsWorld.com helped me to set this up. I have linked his article in the references section as well.

1. Install Jenkins and UiPath Plugin

  • Install Java Development Kit (JDK)
  • Add JDK to PATH
  • Download and install Jenkins
  • Run Jenkins on localhost 8080
  • Install UiPath Plugin within Jenkins

Reference: Jenkins installation on Windows 10 | How to install Jenkins CI on Windows 10 - YouTube

Pitfall

  • Take care to install a version of JDK that Jenkins is compatible with. As on this date, this version is 11. Find out the latest supported version here: Java requirements
  • During the installation, select Run service as LocalSystem even though it isn’t recommended

image

Install the UiPath Plugin within Jenkins:

Note: If your Jenkins workspace is set to a folder within the WINDOWS folder (which is usually the case… a path such as C:\WINDOWS\system32\config\systemprofile\AppData\Local\Jenkins.jenkins\workspace), you need to carry out an additional step for the UiPath plugin to work. You need to change this folder to one outside WINDOWS. To do this, navigate to the ‘config.xml’ file within your Jenkins folder to modify the workspace and the builds directories…

<workspaceDir>C:/JenkinsRoot/${ITEM_FULL_NAME}/workspace</workspaceDir>
<buildsDir>C:/JenkinsRoot/${ITEM_FULL_NAME}/builds</buildsDir> 

… and restart Jenkins.

What this achieves is that it changes my workspace and build directories to ‘C:/JenkinsRoot’. Feel free to come up with a more creative name.

Reference: How to change workspace and build record Root Directory on Jenkins? - Stack Overflow

2. Clone Github Repo

Note: The Jenkinsfile is written in Groovy syntax. Within it, you can see the various stages of the pipeline:
Build → Test → Deploy to UAT-> Deploy to Production
I’ve included the full code within the Jenkinsfile at the end of this post.

To replicate the demo, you need to input your own orchestrator details into this file against the following variables:

UIPATH_ORCH_URL = "https://cloud.uipath.com/"
UIPATH_ORCH_LOGICAL_NAME = "anupaminc"
UIPATH_ORCH_TENANT_NAME = "Descriptify"
UIPATH_ORCH_FOLDER_NAME = "Default"

You can find these values in your automation cloud instance. Navigate to Admin → Tenant → API Access

image

image

Now note down the value in the ‘User Key’ field carefully. You’ll need to supply it to Jenkins as a credential in a later step.

Also, ensure that the environment mentioned in the ‘Deploy to UAT’ stage in the Jenkinsfile matches with the name of an environment in your orchestrator:

stage('Deploy to UAT') {
	            steps {
	                 ...
	                 ...
	                environments: 'DEV',
	                //credentials: [$class: 'UserPassAuthenticationEntry', credentialsId: 'APIUserKey']
	                credentials: Token(accountName: "${UIPATH_ORCH_LOGICAL_NAME}", credentialsId: 'APIUserKey'), 
...

Pitfall: Once you have made the necessary changes to the Jenkinsfile, commit and push to the Github repository before proceeding further. Further, the name “Jenkinsfile” is case specific and the file should not have any extension such as “.txt”.

3. Setup Jenkins Pipeline

Before we get to the pipeline itself, we need to create a credential for the API User Key we obtained earlier to the UiPath Orchestrator.

In Jenkins, add a global credential for the API key. Navigate to Jenkins → Manage Jenkins → Manage Credentials. You should see the following screen:

Click on ‘global’ → Add Credentials. In the ‘Kind’ dropdown, select Secret Text.

Enter your API User Key in the secret field. In the ID field, be sure to enter “APIUserKey” as the value. This is how the code in the Jenkinsfile refers to this credential. Click ‘OK’ after including a helpful description.

We are now ready to create our Jenkins pipeline. Navigate to Jenkins → New Item. Enter a suitable name, select Multibranch Pipeline and click OK

In the Branch Sources tab, select Add Source → Github:

In the Repository HTTPS URL field, enter the URL to your Github repository and click Save.

image

That is pretty much it… If everything is setup perfectly, Jenkins should show you the following screen with the status as “Finished: SUCCESS.”

image

Jenkins should have replicated the structure of your Github repository. Within the master branch, you should see that the pipeline has successfully created a build:

And this build should appear (like magic!) in your orchestrator instance too:

image

Pitfall: If you haven’t moved the workspace directory outside of the windows folder as I have indicated in step 1, you are likely to encounter the following error message:

ERROR: The plugin cannot be executed in a workspace path inside the WINDOWS folder. Please use a custom workspace folder that is outside the WINDOWS folder for this build definition or reinstall Jenkins and use a local user account instead.
Finished: FAILURE

If so, change the Jenkins config file as indicated in step 1 above.

Otherwise, if you have received a success message, congratulations! Let us now see how we can configure your pipeline to build new versions and push them to UiPath orchestrator as soon as the code in your Github repository is updated.

4. Connect Git Repo for automated builds when new commits are made

As with most things, there is an easy way and a hard, but elegant way to do this:

The easy way is to check for new builds is to have Jenkins periodically poll your github repository and check if new code has been committed. You can do this by navigating to Jenkins Pipeline → Configure → Scan Repository Triggers.

image

image

The limitation here is that updates happen only at a set frequency - not as soon as code is committed. Another factor is that Jenkins imposes limitations on polling Git repositories for updates.

The hard, but elegant way is to configure webhooks:

Github Repo → Settings → Webhooks → Add Webhook

On taking that path, you should see the following form. Here, you need to specify the URL to your Jenkins server followed by “/github-webhook/”

Select “application/x-www-form-urlencoded” as the type and the “Just the push event” radio button before creating the webhook.

image

Pitfall: If you’re running Jenkins on your local machine “E.g. localhost:8080”, Github mostly won’t be able to access it since it sits behind a firewall, even if you provide your public IP address in the place of “localhost”. To get around this, you need a secure tunneling service. For the purpose of this demo, I used Ngrok, and it worked quite well.

Reference: ngrok - download

Next Steps
Alright! So you have gotten this far. Where can you go from here? I suggest you explore the following topics

  • Try configuring a webhook if you didn’t do that already
  • Try setting this up for a private Github repo (hint: you’ll need a username and a private access token)
  • Break the code within the Jenkinsfile to see how it works
  • Use the UiPath plugin to generate additional code to add to the Jenkinsfile
  • Wait for part 2 of this series, which will explain how you include Testing

References:

Jenkinsfile text

pipeline {
 agent any

    	        // Environment Variables
	        environment {
	        MAJOR = '1'
	        MINOR = '0'
	        //Orchestrator Services
	        UIPATH_ORCH_URL = "https://cloud.uipath.com/"
	        UIPATH_ORCH_LOGICAL_NAME = "anupaminc"
	        UIPATH_ORCH_TENANT_NAME = "Descriptify"
	        UIPATH_ORCH_FOLDER_NAME = "Default"
	    }
	

	    stages {
	

	        // Printing Basic Information
	        stage('Preparing'){
	            steps {
	                echo "Jenkins Home ${env.JENKINS_HOME}"
	                echo "Jenkins URL ${env.JENKINS_URL}"
	                echo "Jenkins JOB Number ${env.BUILD_NUMBER}"
	                echo "Jenkins JOB Name ${env.JOB_NAME}"
	                echo "GitHub BranhName ${env.BRANCH_NAME}"
	                checkout scm
	

	            }
	        }
	

	         // Build Stages
	        stage('Build') {
	            steps {
	                echo "Building..with ${WORKSPACE}"
	                UiPathPack (
	                      outputPath: "Output\\${env.BUILD_NUMBER}",
	                      projectJsonPath: "project.json",
	                      version: [$class: 'ManualVersionEntry', version: "${MAJOR}.${MINOR}.${env.BUILD_NUMBER}"],
	                      useOrchestrator: false
	        )
	            }
	        }
	         // Test Stages
	        stage('Test') {
	            steps {
	                echo 'Testing..the workflow...'
	            }
	        }
	

	         // Deploy Stages
	        stage('Deploy to UAT') {
	            steps {
	                echo "Deploying ${BRANCH_NAME} to UAT "
	                UiPathDeploy (
	                packagePath: "Output\\${env.BUILD_NUMBER}",
	                orchestratorAddress: "${UIPATH_ORCH_URL}",
	                orchestratorTenant: "${UIPATH_ORCH_TENANT_NAME}",
	                folderName: "${UIPATH_ORCH_FOLDER_NAME}",
	                environments: 'DEV',
	                //credentials: [$class: 'UserPassAuthenticationEntry', credentialsId: 'APIUserKey']
	                credentials: Token(accountName: "${UIPATH_ORCH_LOGICAL_NAME}", credentialsId: 'APIUserKey'), 
	

	        )
	            }
	        }
	

	

	         // Deploy to Production Step
	        stage('Deploy to Production') {
	            steps {
	                echo 'Deploy to Production'
	                }
	            }
	    }
	

	    // Options
	    options {
	        // Timeout for pipeline
	        timeout(time:80, unit:'MINUTES')
	        skipDefaultCheckout()
	    }
	

	

	    // 
	    post {
	        success {
	            echo 'Deployment has been completed!'
	        }
	        failure {
	          echo "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.JOB_DISPLAY_URL})"
	        }
	        always {
	            /* Clean workspace if success */
	            cleanWs()
	        }
	    }
	

	}
23 Likes

Informative @anupamck :clap:t2::clap:t2::clap:t2::clap:t2::fire:

2 Likes

Thank you very much for sharing your knowledge @anupamck :smiley:

1 Like

A pleasure, Stefan. Thanks for your guidance and encouragement!

1 Like

Thank You, @NIVED_NAMBIAR!

1 Like

This is exactly what I was looking for, never found such a detailed guide. Thank you @anupamck. This should be added to docs.uipath.com if possible !

3 Likes

Thank you @Nithin_P - glad you found it useful :slight_smile:

2 Likes

Thank you so much for this through walkthrough!

After adhering to all steps and pitfalls It fails at UAT as shown in the images provided.

Also not I was able to access Jenkins by logging in as a service.

Hi Alicia - sorry that I was away for so long! I was on vacation and didn’t have access to the forum.

Is your issue resolved in the meantime? I see that you received a CLI error during the UiPath Deploy step within the UAT stage. However, in your logs screenshot, I don’t see this step or the detailed error message mentioned.

I see that you have posted a ‘Scan Repository Log’. If you’re still troubleshooting this, please take a snapshot of the ‘Console Output’ log? It would look something like this:

Hi Anupam,

I m seeing stages as failed … i have corrected the config.xml also but still see stages in failure. PFB screenshot for reference:

Hello Devashish - I see that your pipeline encounters an error in the Build stage. Could you please post a screenshot of your console output for any of these runs?

@anupamck - Been going through bits and pieces of CICD for a long time. You have given everything in a platter. Works like a charm. :slight_smile:
Have to do some R&D for production deployment still this is awesome for a start. Thanks a ton…!! :handshake:

1 Like

Hi @JithinKP - glad to have been of help :slight_smile:

Here’s some documentation on the UiPath Jenkins plugin - the basis on which the Jenkinsfile in my repo is built. You can check out several other snippets to include here: https://plugins.jenkins.io/uipath-automation-package/

1 Like


@anupamck - Will definitely do. Thank you :slight_smile:

Hmm - your screenshots indicate that you have encountered an error because of the workspace folder being within the WINDOWS directory. I also see that your config.xml file looks good.

Here’s one last check - Have you created the following folder before running the pipeline → “C:/Jenkinsroot”? If not, can you create this folder and try running the pipeline again?


already created it

I have pinged you on LinkedIn to coordinate and find a solution.

2 Likes

@anupamck very detailed guide, thank you. I hope more discussion on integrating CI/CD into ui path / RPA in general happens in the future.

1 Like