In this article, I have tried to give a simplistic view of the integration required for the implementation of CI-CD tools- GIT and Jenkins with UiPath. A similar guide is already published for Azure Pipelines.
In this article, we have covered –
Let’s get started!
Jenkins introduces a domain-specific language (DSL) based on ‘Groovy’, which can be used to define a new pipeline as a script.
Similar to Azure UiPath Pipelines Example, we have two options to create our pipelines.
For this article, we are going to use the “UiPath Jenkins Plugin” to create pipelines using the “Jenkins File” kept inside project folder…
Jenkinsfile is a text file that contains the definition of a Jenkins Pipeline.The different organization has a different approach to building pipelines, however creating a Jenkinsfile, which is checked into source control provides below benefits –
[You can skip this section if you are already aware of basic terminologies of DevOps implementation]
As discussed above, the definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which in turn can be committed to a project’s source control repository.
The following concepts are key aspects of Jenkins Pipeline-
There are few other levels and options which are also required if you wish to create more complex example. You can read the syntax of Pipeline here. (Pipelines syntax)
A Jenkins file (Pipeline) can be written in two types of syntax-
Declarative – is a relatively new addition to pipeline syntax and provide a simplified way to get started with the configuration to perform various steps.
(Imposes limitations to the user with a much stricter and pre-defined structure)
Scripted– Scripted Pipelines can include and make use of any valid Groovy code.
Syntax Comparison:
Consider the following Pipeline which implements a basic three-stage continuous delivery pipeline.
The most fundamental part of a pipeline is “steps”, which tell Jenkins what to do and serve as a basic building block.
You should be able to construct a more complex example using Directives and Steps.
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building...'
}
}
stage('Test') {
steps {
echo 'Testing...'
}
}
stage('Deploy') {
steps {
echo 'Deploying....'
}
}
}
}
We will see this in details in next section when we create pipeline for UiPath project.
The UiPath Jenkins Plugin allows you to integrate RPA development and Software Testing with UiPath into Jenkins.
It provides build tasks to pack UiPath projects into nuget packages, deploy them to Orchestrator and run Test Sets on Orchestrator.
Jenkins Pipeline exposes environment variables via the global variable env, which is available from anywhere within a Jenkinsfile.
Environment variables are accessible from Groovy code as env.VARNAME or simply as VARNAME. You can write to such properties as well (only using the env. prefix).
Below are few common environment variables we will use inside our pipeline.
(The full list of environment variables accessible from within Jenkins Pipeline is documented at ${YOUR_JENKINS_URL}/pipeline-syntax/globals#env)
Note –
Jenkins’ declarative Pipeline syntax has the credentials() helper method (used within the environment directive) which supports secret text, username and password, as well as secret file credentials.
You can create Credentials by Navigating to Credentials Page and selecting the Store (Logical group to separate access).
For our example, we need to store basic username and password if using on-perm orchestrator or user APIKEY in case you are using cloud orchestrator.
Supported Credentials Type:
Declarative Pipeline supports robust failure handling by default via its post section which allows declaring a number of different “post conditions” such as: always, unstable, success, failure, and changed.
Example Syntax.(You can do many steps here like sending email, approval, Slack Notification etc…)
post
{
changed
{
echo "Status has changed"
}
failure
{
echo "Status is failure"
//You can post your failure message here
}
success
{
echo "Status is success"
//You can post your failure message here and probably you wish to send email to notification
}
unstable
{
echo "Status is unstable"
}
aborted
{
echo "Status is aborted"
//Good to send Slack Notification when aborted
}
always {
script {
BUILD_USER = getBuildUser()
}
echo 'I will always say hello in the console.'
slackSend channel: '#slack-test-channel',
color: COLOR_MAP[currentBuild.currentResult],
message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} by ${BUILD_USER}\n More info at: ${env.BUILD_URL}"
}
}
So far so good, we have covered almost all the basic details we need to Build our UiPath Pipeline.
At this point of article, I assume you have.
Let’s see our pipeline working – (We will do it in two steps)
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
You’re now ready to create the Pipeline that will automate building your UiPath Project in Jenkins.
pipeline {
agent any
// Environment Variables
environment {
MAJOR = '1'
MINOR = '0'
//Orchestrator Services
UIPATH_ORCH_URL = "https://cloud.uipath.com/"
UIPATH_ORCH_LOGICAL_NAME = "AIFabricDemo"
UIPATH_ORCH_TENANT_NAME = "UATdfds611009"
UIPATH_ORCH_FOLDER_NAME = "Shared"
}
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()
}
}
}
Lets quickly run the Build to see the results.
If everything goes well you should be able to see the published package inside your orchestrator instance.
When installing a service to run under a domain user account, the account must have the right to logon as a service on the local.
Perform the following to edit the Local Security Policy of the computer you want to define the ‘logon as a service’ permission:
Refer Jenkins installation setup
Sign in to your account