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:
- Install Jenkins and UiPath Plugin
- Clone Github Repo
- Setup Jenkins Pipeline
- 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
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
- Clone the Github repo UiPath_Jenkins_CICDDemo from the following link: GitHub - descriptify/UiPath_Jenkins_CICDDemo
- Open the Jenkinsfile in the repo with your favourite IDE within the repository and modify it:
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
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.
That is pretty much it⌠If everything is setup perfectly, Jenkins should show you the following screen with the status as âFinished: SUCCESS.â
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:
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.
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.
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:
- Preview this in action: UiPath, Jenkins CICD Pipeline - Part 1 - YouTube
- RPA Bots World - Implementing CI CD in UiPath using Jenkins plugin
- Jenkins Installation - Jenkins installation on Windows 10 | How to install Jenkins CI on Windows 10 - YouTube
- How to change workspace and build record Root Directory on Jenkins? - Stack Overflow
- Ngrok download - ngrok - download
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,
traceLevel: 'None'
)
}
}
// 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'),
traceLevel: 'None',
entryPointPaths: 'Main.xaml'
)
}
}
// 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()
}
}
}