Jenkins Shared Library Documentation

Table of Contents

Global Methods

Classes

Global Methods

argocd
File: argocd.groovy
Pipeline step to interact with ArgoCD, supported actions - Deploy, ConfigUpdate and Restart
Parameters:
  • config: (Map) - This is split into the below params, use it inside the map (varies based on action)
  • action: (String) MANDATORY valid values - 'DEPLOY', 'CONFIG_UPDATE', 'RESTART'
  • argoCdUsername: (String) MANDATORY ArgoCD Username to authenticate
  • argoCdPassword: (String) MANDATORY ArgoCD password for the user
  • argoCdAppName: (Map) MANDATORY ArgoCD appname to work with
  • argoCdDomain: (String) MANDATORY ArgoCD domain where the server is hosted
  • configMapName: (String) MANDATORY when action is CONFIG_UPDATE The name of configmap to update.
  • deployments: (List<String>) MANDATORY when action is CONFIG_UPDATE / RESTART The name of deplyoments to restart.
Example:
argocd action: 'DEPLOY', argoCdUsername: 'platform-argocd', argoCdPassword: 'abcd1234', argoCdAppName: 'blink-us', argoCdDomain: 'argocd.surveysparrow.com'
argocd action: 'RESTART', argoCdUsername: 'platform-argocd', argoCdPassword: 'abcd1234', argoCdAppName: 'blink-us', argoCdDomain: 'argocd.surveysparrow.com', deployments: ['blink', 'blink-resync']
deploy
File: argocd.groovy
Deploy an application through ArgoCD. Logs in to argocd, syncs the given app, logs out of argocd
Parameters:
  • config: (Map) - This is split into the below params.
  • argoCdUsername: (String) MANDATORY ArgoCD Username to authenticate
  • argoCdPassword: (String) MANDATORY ArgoCD password for the user
  • argoCdAppName: (Map) MANDATORY ArgoCD appname to work with
  • argoCdDomain: (String) MANDATORY ArgoCD domain where the server is hosted
configUpdate
File: argocd.groovy
Update the configmap of application through ArgoCD. Logs in to argocd, updates configmap of the given app, logs out of argocd
Parameters:
  • config: (Map) - This is split into the below params.
  • argoCdUsername: (String) MANDATORY ArgoCD Username to authenticate
  • argoCdPassword: (String) MANDATORY ArgoCD password for the user
  • argoCdAppName: (Map) MANDATORY ArgoCD appname to work with
  • argoCdDomain: (String) MANDATORY ArgoCD domain where the server is hosted
  • configMapName: (String) MANDATORY The name of configmap to update.
  • deployments: (List<String>) MANDATORY The name of deplyoments to restart.
  • async: (Boolean) OPTIONAL If true, doesn't wait for sync completion. Defaults to false.
  • timeout: (Number) OPTIONAL Time in seconds to wait for sync completion. Defaults to 1200 (20 minutes).
restart
File: argocd.groovy
Restart an application through ArgoCD. Logs in to argocd, restarts given deployments, logs out of argocd
Parameters:
  • config: (Map) - This is split into the below params.
  • argoCdUsername: (String) MANDATORY ArgoCD Username to authenticate
  • argoCdPassword: (String) MANDATORY ArgoCD password for the user
  • argoCdAppName: (Map) MANDATORY ArgoCD appname to work with
  • argoCdDomain: (String) MANDATORY ArgoCD domain where the server is hosted
  • deployments: (List<String>) MANDATORY The name of deplyoments to restart.
syncKustomizeApp
File: argocd.groovy
Refresh and Sync any applications managed by Kustomize through ArgoCd.
Parameters:
  • config: (Map) - This is split into the below params.
  • argoCdUsername: (String) MANDATORY ArgoCD Username to authenticate
  • argoCdPassword: (String) MANDATORY ArgoCD password for the user
  • argoCdAppName: (Map) MANDATORY ArgoCD appname to work with
  • argoCdDomain: (String) MANDATORY ArgoCD domain where the server is hosted
updateKustomizeApp
File: argocd.groovy
Refresh and Sync Kustomize applications without waiting for sync completion.
Parameters:
  • config: (Map) - This is split into the below params.
  • argoCdUsername: (String) MANDATORY ArgoCD Username to authenticate
  • argoCdPassword: (String) MANDATORY ArgoCD password for the user
  • argoCdAppName: (Map) MANDATORY ArgoCD appname to work with
  • argoCdDomain: (String) MANDATORY ArgoCD domain where the server is hosted
createAndApplyConfigMap
File: createAndApplyConfigMap.groovy
Create and apply a config map to the kubernetes cluster
Parameters:
  • config: (Map) - This is split into the below params, use it inside the map.
  • cmName: (String) MANDATORY The name of the configmap
  • namespace: (String) MANDATORY The namespace where to apply the configmap
  • data: (Map) MANDATORY The data for the configmap as key value pairs
Example:
createAndApplyConfigMap cmName: 'surveysparrow-config-a', namespace: 'surveysparrow', data: [euiDistVersion: '1234']
build
File: dockerUtils.groovy
Docker Build Utility for Jenkins Pipelines
Parameters:
  • dockerfile: (String) Path to the Dockerfile. Default: 'Dockerfile'.
  • repo: (String) The docker repository to tag the image with.
  • tags: (List<String>) List of tags to apply to the image. Default: [].
  • buildArgs: (Map<String, String>) Map of build arguments to pass. Default: [:].
  • additionalArgs: (List<String>) Additional Docker build flags. Default: [].
push
File: dockerUtils.groovy
Push the docker image to the docker repository
Parameters:
  • repo: (String) the docker repository to push the image
  • tags: (List<String>) the tags of the image
authenticate
File: dockerUtils.groovy
Authenticate to docker registry
Parameters:
  • registry: (String) the docker registry url (ECR, Dockerhub)
  • region: (String) the region where the docker registry resides
  • config: (Map) the config for cross account authentication
clearAuth
File: dockerUtils.groovy
Clear the set authentication credentials incase of cross account authentication
pruneAllImages
File: dockerUtils.groovy
Prune all the docker images
getJobLastSuccessfulDuration
File: getJobLastSuccessfulDuration.groovy
Pipeline step to get the last successful duration of a job
Parameters:
  • jobName: (String) the name of the job to fetch the last successful duration
  • averageDeploymentTime: (Number) Optional the time to return if last successful is null. (Default: 900000, 15mins)
Returns: lastSuccessfulBuildDuration (Number) the time taken by in ms for the last successful job
cloneRepoWithGit
File: gitUtils.groovy
Clones a repository from source control repository using pipeline step git.
Parameters:
  • branch: The branch to clone.
  • repoUrl: The repository URL.
  • credentialId: The Jenkins credentials ID.
Returns: clones the repo in the current working directory.
cloneRepo
File: gitUtils.groovy
Clones a repository from source control repository using pipeline checkout scmGit().
Parameters:
  • branch: The branch to clone.
  • repoUrl: The repository URL.
  • credentialId: The Jenkins credentials ID.
Returns: clones the repo in the current working directory.
checkoutMergeAndPush
File: gitUtils.groovy
Checkout source code from a source branch and merge to target branch
Parameters:
  • sourceBranch: (String) The source branch to checkout
  • targetBranch: (String) The target branch to merge the source branch to
commitAndPush
File: gitUtils.groovy
Commit and push the code to specified branch
Parameters:
  • branch: (String) The target branch to push the commit to
  • message: (String) The commit message
  • filePath: (String) OPTIONAL The specific file to commit (Default - . (all files))
setGitConfig
File: gitUtils.groovy
Set the Git Config for username and email from common constants
getCommitHash
File: gitUtils.groovy
Get the commit hash from the repository
Parameters:
  • useShort: (Boolean) Optional - whether to return the short or long commit hash (Default: true)
Returns: commitHash (String) The commit hash in short or long format
createBranch
File: gitUtils.groovy
Create a new branch in the repository
Parameters:
  • branchName: (String) The name of the branch to create
  • sourceBranch: (String) The source branch to create the new branch from
createSubmoduleBranch
File: gitUtils.groovy
Create a new branch in the repository
Parameters:
  • branchName: (String) The name of the branch to create
  • sourceBranch: (String) The source branch to create the new branch from
getHeadViaAPI
File: gitUtils.groovy
Get HEAD of the repository
Parameters:
  • repository: (String) The repository to get the HEAD of
  • branch: (String) The branch to get the HEAD of
  • apiToken: (String) The Bitbucket API token
Returns: (String) The HEAD of the repository
getSubmoduleRepos
File: gitUtils.groovy
Get all submodule repositories
Parameters:
  • repository: (String) The repository to get the submodule repositories for
  • branch: (String) The branch to get the submodule repositories for
  • apiToken: (String) The Bitbucket API token
Returns: (List) A list of submodule repositories
createPullRequest
File: gitUtils.groovy
Create a pull request using Bitbucket API
Parameters:
  • sourceBranch: (String) The source branch name
  • repository: (String) The repository in format 'workspace/repo_name'
  • apiToken: (String) The Bitbucket API token
  • targetBranch: (String) The target branch (default: 'master')
  • title: (String) The PR title (optional, will be auto-generated if not provided)
  • description: (String) The PR description (optional)
Returns: (Map) Response object containing PR details or error information
getChangedFiles
File: gitUtils.groovy
Get a list of changed files in the latest commit
Returns: (List) A list of changed files with their status (A=Added, M=Modified, D=Deleted, R=Renamed)
getLatestTag
File: gitUtils.groovy
Get the latest tag from the repository
Parameters:
  • prefix: (String) The prefix of the tag to get
Returns: (String) The latest tag in the repository. If no tag is found, it returns 'v1.0.0'
createTag
File: gitUtils.groovy
Create a new tag in the repository
Parameters:
  • tagName: (String) The name of the tag to create
  • message: (String) The message to associate with the tag
pushTag
File: gitUtils.groovy
Push a tag to the repository
Parameters:
  • tagName: (String) The name of the tag to push
ifInstallNodeModules
File: ifInstallNodeModules.groovy
Check whether to install node_modules or not. Given the referencefile, S3 bucket and path.
Parameters:
  • referenceFile: (String) The file to watch the changes for, get the md5sum for (eg. package.json, package-lock.json)
  • bucket: (String) The S3 bucket to check and upload the node_modules directory
  • path: (String) The path where to upload or download the node_modules from
Returns: md5Hash (String) The md5 hash of the reference file so you can pull the tar file wherever in the pipeline
getProjectInfo
File: jira.groovy
Get project information by project key
Parameters:
  • projectKey: (String) the Jira project key
  • tokenCredentialId: (String) the credential ID for Jira API token (Default = 'JiraAuthToken')
  • jiraUrl: (String) the Jira instance URL (Default = 'https://surveysparrow.atlassian.net')
Returns: (Map) project information
createJiraRelease
File: jira.groovy
Create a new Jira release/version
Parameters:
  • projectKey: (String) the Jira project key (e.g., 'SSE', 'SDE')
  • versionName: (String) the name of the version to create
  • description: (String) optional description for the version
  • startDate: (String) optional start date in YYYY-MM-DD format
  • releaseDate: (String) optional release date in YYYY-MM-DD format
  • tokenCredentialId: (String) the credential ID for Jira API token (Default = 'JiraAuthToken')
  • jiraUrl: (String) the Jira instance URL (Default = 'https://surveysparrow.atlassian.net')
Returns: (Map) response containing version information
versionExists
File: jira.groovy
Get all versions for a Jira project
Parameters:
  • projectKey: (String) the Jira project key
  • tokenCredentialId: (String) the credential ID for Jira API token (Default = 'JiraAuthToken')
  • jiraUrl: (String) the Jira instance URL (Default = 'https://surveysparrow.atlassian.net')
  • projectKey: (String) the Jira project key
  • versionName: (String) the name of the version to check
  • tokenCredentialId: (String) the credential ID for Jira API token (Default = 'JiraAuthToken')
  • jiraUrl: (String) the Jira instance URL (Default = 'https://surveysparrow.atlassian.net')
Returns: (List) list of versions for the project
getVersionInfo
File: jira.groovy
Get version information by name
Parameters:
  • projectKey: (String) the Jira project key
  • versionName: (String) the name of the version to get
  • tokenCredentialId: (String) the credential ID for Jira API token (Default = 'JiraAuthToken')
  • jiraUrl: (String) the Jira instance URL (Default = 'https://surveysparrow.atlassian.net')
Returns: (Map) version information
releaseVersion
File: jira.groovy
Release a version in Jira (mark as released)
Parameters:
  • versionId: (String) the ID of the version to release
  • tokenCredentialId: (String) the credential ID for Jira API token (Default = 'JiraAuthToken')
  • jiraUrl: (String) the Jira instance URL (Default = 'https://surveysparrow.atlassian.net')
Returns: (Map) response containing operation result
createVersionIfNotExists
File: jira.groovy
Create version if it doesn't exist and optionally release it
Parameters:
  • config: (Map) configuration map containing:
Returns: (Map) response containing version information
checkIfDeploymentExists
File: k8s.groovy
Check if a deployment with a given name exists in a give namespace. Internal method, to use separately, must authenticate to CloudProvider
Parameters:
  • deploymentName: (String) the name of the deployment to check
  • namespace: (String) the namespace to check if the deployment exists
restartDeployment
File: k8s.groovy
Restart a given deployment in a given namespace. Cloud authentication is handled within the method.
Parameters:
  • deploymentName: (String) the name of the deployment to restart
  • namespace: (String) the namespace in which the deployment exists
apply
File: k8s.groovy
Apply a give yaml file from the specified path
Parameters:
  • filePath: (String) the path where the YAML file resides
  • kustomize: (Boolean) if the apply is kustomize. (Default = false)
create
File: k8s.groovy
Create a resource from the given yaml file from the specified path, this can be used for Jobs
Parameters:
  • filePath: (String) the path where the YAML file resides
  • kustomize: (Boolean) if the apply is kustomize. (Default = false)
waitForCondition
File: k8s.groovy
Wait for a condition to be satisfied
Parameters:
  • condition: (String) the condition to wait for
  • resource: (String) the type of resource to wait on
  • selector: (Map) the label selector to identify the resource
  • namespace: (String) the namespace in which the resource resides
  • timeout: (int) the timeout in seconds (Default = 15)
waitUntilJobCompletion
File: k8s.groovy
Wait for a job to complete based on labels
Parameters:
  • labels: (Map) the labels in a key:value format, this will perform an AND label operation.
  • namespace: (String) the namespace in which the job resides.
  • timeout: (int) the timeout in minutes (Default = -1) which means wait for one week.
authenticate
File: k8s.groovy
Authenticate to a Kubernetes cluster
Parameters:
  • clusterName: (String) the name of the Kubernetes cluster
  • region: (String) the region in which the kubernetes cluster resides
  • config: (Map) Optional - Cross account config if kubernetes cluster is in another account.
hasJobSucceededByLabels
File: k8s.groovy
Check if a Kubernetes job has succeeded using labels
Parameters:
  • selector: (Map) the label selector to identify the job
  • namespace: (String) the namespace in which the job resides
Returns: boolean indicating if the job has succeeded
hasJobSucceededByName
File: k8s.groovy
Check if a Kubernetes job has succeeded
Parameters:
  • jobName: (String) the name of the job
  • namespace: (String) the namespace in which the job resides
Returns: boolean indicating if the job has succeeded
clearAuth
File: k8s.groovy
Clear the authentication credentials if authenticated across accounts
delete
File: k8s.groovy
Delete a kubernetes object in the specified namespace
Parameters:
  • resource: (String) the kind of the resource.
  • resourceName: (String) the name of the resource.
  • namespace: (String) the namespace where the resource resides.
watchLogs
File: k8s.groovy
Watch logs of a pod based on labels
Parameters:
  • labels: (Map) the labels in a key:value format, this will perform an AND label operation.
  • namespace: (String) the namespace in which the pod resides.
logToFile
File: k8s.groovy
Get logs of a pod based on labels
Parameters:
  • labels: (Map) the labels in a key:value format, this will perform an AND label operation.
  • namespace: (String) the namespace in which the pod resides.
  • filePath: (String) the path to write the logs to
liveLogs
File: k8s.groovy
Print live logs of a pod based on labels. This method will wait for the pod to be ready and then print the logs.
Parameters:
  • selector: (String) the label selector to identify the pod
  • namespace: (String) the namespace in which the pod resides
  • readinessTimeout: (int) the timeout in seconds to wait for the pod to be ready
  • activeDeadline: (int) the timeout in seconds for the job to complete
getPendingPodsCountByLabels
File: k8s.groovy
Get the count of pending pods based on labels
Parameters:
  • labels: (Map) the labels in a key:value format
  • namespace: (String) the namespace in which the pods reside
Returns: (int) the count of pending pods
labelBuilderFromMap
File: k8s.groovy
Build a label selector from a map of labels
Parameters:
  • labels: (Map) the labels in a key:value format
Returns: (String) the label selector
deleteJob
File: k8s.groovy
Delete a job based on labels
Parameters:
  • labels: (Map) the labels in a key:value format
  • namespace: (String) the namespace in which the job resides
scaleDeployment
File: k8s.groovy
Scale a kubernetes deployment
Parameters:
  • deployment: (String) the name of the deployment to scale
  • replicas: (int) the number of replicas to scale to
  • namespace: (String) the namespace in which the resource resides
rolloutStatusByLabel
File: k8s.groovy
Wait for a rollout to complete based on kubernetes labels
Parameters:
  • labelSelector: (String) the label to select the deployment.
  • namespace: (String) the namespace in which the deployment resides.
restartByLabel
File: k8s.groovy
Restart a kubernetes Deployment by a given label or labels.
Parameters:
  • labels: (Map) the labels in a key:value format, this will perform an AND label operation.
  • namespace: (String) the namespace in which the deployment resides.
patchResource
File: k8s.groovy
Patch a kubernetes resource
Parameters:
  • resource: (String) the kind of the resource
  • name: (String) the name of the resource
  • patch: (String) the patch to apply to the resource
  • namespace: (String) the namespace in which the resource resides
loadConstants
File: loadConstants.groovy
Load and return the constants from org-wide global constants, product-wide constants, environment-specific constants.
Returns: the config as a HashMap Object
Example:
variables = loadConstants()
echo "${variables.KEY_NAME}"
deepMerge
File: loadConstants.groovy
Performs a deep merge of source map into target map
Parameters:
  • target: The target map to merge into
  • source: The source map to merge from
Returns: The merged target map
loadResourceFile
File: loadResourceFile.groovy
Load a resourcefile from resources/ directory of shared libraries. It writes the file in the current
Parameters:
  • resourcePath: (String) The path of the resource file in resources/ directory of shared libraries.
Example:
loadResourceFile('global/jirahelper.py')
runScriptAsJob
File: runScriptAsJob.groovy
Run a kubernetes job from a given YAML file and print logs of the job if needed.
Parameters:
  • config: (Map) This is split into the below params
  • filePath: (String) MANDATORY The path of the kubernetes job YAML file
  • selector: (Map) MANDATORY The kubernetes label selector to identify the pods of the Job E.g. ['migration/type': 'PRE', 'migration/id': "${commit}", 'migration/build': "${env.BUILD_NUMBER}"]
  • namespace: (String) MANDATORY The namespace in which the Job is running in
  • log: (Boolean) Optional. Whether to print the logs or not
  • readinessTimeout: (int) Optional. The timeout in seconds to wait for the pod to be ready
  • activeDeadline: (int) Optional. The timeout in seconds for the job to complete
  • environment: (Map) Optional. Key value of environment to substitute in the Job YAML
sendProgressMessage
File: sendProgressMessage.groovy
Send the progress message as seen in #production-deployments channel for deployments
Parameters:
  • config: (Map) This is split into the below params
  • messageType: (String) one of the values 'DEPLOYMENT_STARTED', 'DEPLOYMENT_SUCCESSFUL', 'DEPLOYMENT_FAILED', 'DEPLOYMENT_ABORTED'
  • application: (String) The application for which the deployment message is sent
Returns: msgTimestamp (String) The message timestamp to send further messages
getSlackUserTag
File: slack.groovy
Get Slack user tag from email address
Parameters:
  • email: (String) the email address of the user
  • botUser: (Boolean) whether to use bot user token (Default = true)
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (String) the Slack user tag in format <@USER_ID>
createChannel
File: slack.groovy
Create a new Slack channel
Parameters:
  • channelName: (String) the name of the channel to create
  • isPrivate: (Boolean) whether the channel should be private (Default = true)
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (Map) response containing channel information
addMembersToChannel
File: slack.groovy
Add members to a Slack channel
Parameters:
  • channelId: (String) the ID of the channel to add members to
  • userIds: (List) list of user IDs to add to the channel
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (Map) response containing operation result
addMembersToChannelByEmail
File: slack.groovy
Add members to a Slack channel by email addresses
Parameters:
  • channelId: (String) the ID of the channel to add members to
  • emails: (List) list of email addresses to add to the channel
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (Map) response containing operation result
getChannelInfo
File: slack.groovy
Get channel information by name
Parameters:
  • channelName: (String) the name of the channel to get information for
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (Map) response containing channel information
getChannelId
File: slack.groovy
Get channel ID by name
Parameters:
  • channelName: (String) the name of the channel to get ID for
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (String) the channel ID
channelExists
File: slack.groovy
Check if a channel exists
Parameters:
  • channelName: (String) the name of the channel to check
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (Boolean) true if channel exists, false otherwise
createChannelAndAddMembers
File: slack.groovy
Create channel if it doesn't exist and add members
Parameters:
  • channelName: (String) the name of the channel to create
  • emails: (List) list of email addresses to add to the channel
  • isPrivate: (Boolean) whether the channel should be private (Default = true)
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (Map) response containing channel information
createChannelAndAddByUserIds
File: slack.groovy
Create channel if it doesn't exist and add members by user IDs
Parameters:
  • channelName: (String) the name of the channel to create
  • emails: (List) list of email addresses to add to the channel
  • isPrivate: (Boolean) whether the channel should be private (Default = true)
  • tokenCredentialId: (String) the credential ID for Slack bot token (Default = variables.SLACK_BOT_TOKEN_ID)
Returns: (Map) response containing channel information

Classes

ArgoCd

ArgoCd
File: ArgoCd.groovy
A utility to interact with ArgoCD.
Parameters:
  • script: (reference) The script context to execute shell commands.
  • domain: (String) The domain where argocd is hosted.
  • appName: (String) The application name in argocd.
login
File: ArgoCd.groovy
Login to the ArgoCD Server
Parameters:
  • username: (String) The username to authenticate.
  • password: (String) The password of the give username.
logout
File: ArgoCd.groovy
Logout of the ArgoCD Server
run
File: ArgoCd.groovy
Run any action on the ArgoCD Server
Parameters:
  • action: (String) The action to perform (eg. restart)
  • resource: (String) The resource on which the action is performed. (eg. Deployment)
  • resourceName: (String) The name of the resource which is being modified.
  • timeout: (Number) Optional parameter to wait for the action to complete. (Default: 1200)
sync
File: ArgoCd.groovy
Sync the argocd application
Parameters:
  • resource: (String) Optional parameter the name of the resource to sync. (e.g. :ConfigMap:configmap-name)
  • timeout: (Number) Optional parameter to wait for the sync to complete. (Default: 1200)
  • async: (Boolean) Optional parameter to run the sync asynchronously. If true, won't wait for sync completion. (Default: false)
waitForSync
File: ArgoCd.groovy
Wait for the action on the application to complete
Parameters:
  • timeout: (Number) Optional parameter to wait for the action to complete. (Default: 1200)
refreshAndSync
File: ArgoCd.groovy
Refresh the ArgoCd Cache and force the sync operation.
Parameters:
  • resource: (String) Optional parameter the name of the resource to sync. (e.g. :ConfigMap:configmap-name)
  • timeout: (Number) Optional parameter to wait for the sync to complete. (Default: 1200)
  • async: (Boolean) Optional parameter to run the sync asynchronously. If true, won't wait for sync completion. (Default: false)
hardRefresh
File: ArgoCd.groovy
Hard Refresh the ArgoCd Cache and pull the updated state from the repositories.

CloudAuthManager

CloudAuthManager
File: CloudAuthManager.groovy
CloudAuthManager - contains all the methods to communicate with CloudProviders based on region.
Parameters:
  • script: The script context to execute shell commands.
  • region: the region to which to authenticate to.
  • accountConfig: Hashmap Optional parameter - [ crossAccount: true, roleArn: 'AWSRoleArn', accountId: 'AWS Account ID', duration: 'Duration of the session'(By default 900 seconds) ] InCase of AWS, [ secretFileId: 'JenkinsCredentialID', projectId: 'GCP ProjectId' ] InCase of GCP
authenticateToAWS
File: CloudAuthManager.groovy
Authenticates to AWS Cloud provider, can use roles if cross account auth is needed.
Parameters:
  • config: Optional parameter - a hashmap crossAccount: true, roleArn: 'awsArn', region: 'awsRegion', 'accountId': 'aws account Id' are mandatory parameters
Returns: Environment variables with necessary keys in case of cross account else nothing.
authenticateToGCP
File: CloudAuthManager.groovy
Authenticates to GCP Cloud provider.
authenticateToCloudProvider
File: CloudAuthManager.groovy
Authenticate to Cloud Provider based on the map in common constants.
Returns: cloudProvider as string
clearCredentials
File: CloudAuthManager.groovy
Clear the set credentials so you can proceed with using the Instance role.
authenticateToContainerRegistry
File: CloudAuthManager.groovy
Authenticate to container registry based on cloud provider - ECR or Artifact Registry
Parameters:
  • registry: (String) the registry url to authenticate to in the Cloud Provider (ECR in AWS, Artifact Registry in GCP)
authenticateToK8sCluster
File: CloudAuthManager.groovy
Authenticate to Kubernetes Cluster based on Cloud Provider - EKS or GCP
Parameters:
  • cluster: (String) the clusterName to authenticate to in the Cloud Provider (EKS in AWS, GKE in GCP)

Cloudflare

Cloudflare
File: Cloudflare.groovy
A utility to interact with Cloudflare API.
Parameters:
  • script: (Object) The script context to execute shell commands.
  • zoneId: (String) The Cloudflare zone ID for the domain.
  • apiToken: (String) The Cloudflare API token with required permissions.
  • accountId: (String) The Cloudflare account ID. Default is empty string.
purgeCache
File: Cloudflare.groovy
Purges Cloudflare cache for specified domains and paths.
Parameters:
  • cacheType: (String) MANDATORY The type of cache purge to perform: 'hosts', 'prefixes', or 'files'
  • domains: (List<String>) MANDATORY List of domains for which to purge cache
  • paths: (List<String>) OPTIONAL List of paths to purge. Default is an empty path [""]
Returns: (String) The response from the API call
Example:
def cloudflare = new Cloudflare(this, "zone123456", "${CLOUDFLARE_API_TOKEN}")
cloudflare.purgeCache(
"prefixes",
["example.com", "www.example.com"],
["/blog", "/products"]
)
doesPagesProjectExist
File: Cloudflare.groovy
Installs the Wrangler CLI for Cloudflare Pages deployment.
Parameters:
  • version: (String) The version of Wrangler to install. Default is "4.13.2".
  • projectName: (String) The name of the project to create.
  • productionBranch: (String) The branch to use for production deployments.
  • projectName: (String) The name of the project to deploy.
  • buildDir: (String) The directory containing the build output.
  • branch: (String) The branch to deploy.
  • projectName: (String) The name of the project to check.
Returns: Object The result of the installation command
orderSSLCertificate
File: Cloudflare.groovy
Add a custom domain to the project
Parameters:
  • projectName: (String) The name of the project to add the custom domain to.
  • customDomain: (String) The custom domain to add to the project.
  • projectName: (String) The name of the project to create.
  • productionBranch: (String) The branch to use for production deployments.
  • customDomain: (String) The custom domain to add to the project.
  • hostname: (String) The hostname for which to order the certificate (e.g. "*.staging.example.com")
  • validityDays: (Integer) Optional. The number of days the certificate should be valid for. Default is 90.
  • certificateAuthority: (String) Optional. The certificate authority to use. Default is "google".
  • cloudflareBranding: (Boolean) Optional. Whether to include Cloudflare branding. Default is false.
Returns: Object The result of the domain addition command
Example:
def cloudflare = new Cloudflare(this, "zone123456", "${CLOUDFLARE_API_TOKEN}")
cloudflare.orderSSLCertificate("*.staging.example.com")
createDNSRecord
File: Cloudflare.groovy
Creates a DNS record in Cloudflare.
Parameters:
  • recordType: (String) The type of DNS record (e.g., "CNAME", "A", "TXT")
  • name: (String) The name of the DNS record
  • content: (String) The content/value of the DNS record
  • proxied: (Boolean) Optional. Whether the record should be proxied through Cloudflare. Default is false.
  • ttl: (Integer) Optional. Time to live for the record. Default is 1 (automatic).
Returns: (String) The response from the API call
Example:
def cloudflare = new Cloudflare(this, "zone123456", "${CLOUDFLARE_API_TOKEN}")
cloudflare.createDNSRecord("CNAME", "subdomain.example.com", "target.example.com", true)

CodeMagic

CodeMagic
File: CodeMagic.groovy
A utility to interact with the CodeMagic API.
Parameters:
  • script: (reference) The script context to execute shell commands.
  • codeMagicAppId: (String) The CodeMagic application ID.
  • workflowId: (String) The CodeMagic workflow ID.
  • codeMagicToken: (String) The CodeMagic API token.
triggerCodeMagicDeployment
File: CodeMagic.groovy
Triggers a CodeMagic deployment using the provided parameters.
Parameters:
  • buildParams: (Map) The build parameters payload.
Returns: (Map) A map containing the build ID and response code.
printCompletedBuildStageLogs
File: CodeMagic.groovy
Prints CodeMagic logs for completed build stages.
Parameters:
  • buildData: (Map) The build data returned from CodeMagic API.
printStageLogs
File: CodeMagic.groovy
Prints logs for a specific build stage or subaction.
Parameters:
  • data: (Map) The stage or subaction data. The data is a map with the following keys:
  • name: (String) The name of the stage or subaction.
  • status: (String) The status of the stage or subaction.
cancelCodeMagicDeployment
File: CodeMagic.groovy
Gets the deployment status for a given build ID.
Parameters:
  • buildId: (String) The build ID to check.
  • buildId: (String) The build ID to cancel.
Returns: (Map) A map containing the status code and build data.
getArtifactDownloadUrl
File: CodeMagic.groovy
Gets the download link for the IPA artifact from a build.
Parameters:
  • buildId: (String) The build ID.
Returns: (String) The URL of the IPA artifact, or null if not found.

Ec2

getInstanceIdByTag
File: Ec2.groovy
A utility to interact with AWS EC2.
Parameters:
  • tagName: (String) MANDATORY The tag name to search for
Returns: (String) The instance ID of the matching EC2 instance
createAmiBackup
File: Ec2.groovy
Create an AMI backup from an EC2 instance
Parameters:
  • instanceId: (String) MANDATORY The ID of the EC2 instance to backup
  • amiName: (String) MANDATORY The name to give the AMI
  • description: (String) MANDATORY Description for the AMI
  • tags: (String) MANDATORY Tags to apply to the AMI in AWS CLI format
Returns: (String) The ID of the created AMI
waitForAmiAvailable
File: Ec2.groovy
Wait for an AMI to become available
Parameters:
  • amiId: (String) MANDATORY The ID of the AMI to wait for
  • region: (String) MANDATORY The AWS region where the AMI exists
listAmis
File: Ec2.groovy
List AMIs with a specific name prefix
Parameters:
  • namePrefix: (String) MANDATORY The prefix to filter AMI names
Returns: (List) List of AMIs with their ImageId, Name and CreationDate
getAmiSnapshots
File: Ec2.groovy
Get snapshot IDs associated with an AMI
Parameters:
  • amiId: (String) MANDATORY The ID of the AMI
Returns: (List) List of snapshot IDs associated with the AMI
deregisterAmi
File: Ec2.groovy
Deregister an AMI
Parameters:
  • amiId: (String) MANDATORY The ID of the AMI to deregister
deleteSnapshot
File: Ec2.groovy
Delete an EBS snapshot
Parameters:
  • snapshotId: (String) MANDATORY The ID of the snapshot to delete

Jenkins

jenkinsApiCall
File: Jenkins.groovy
A utility to interact with Jenkins API.
Parameters:
  • params: (Map) MANDATORY Map containing API call parameters:
Returns: (String) The response from the API call
stopService
File: Jenkins.groovy
Check if Jenkins service is active
Parameters:
  • quiet: (boolean) Whether to run the command in quiet mode (default: true)
Returns: (boolean) True if Jenkins is active, false otherwise
startService
File: Jenkins.groovy
Start Jenkins service and wait for it to be fully operational
reloadConfiguration
File: Jenkins.groovy
Reload Jenkins configuration
Parameters:
  • jenkinsUrl: (String) The URL of the Jenkins instance
  • jenkinsApiKey: (String) The API key for authentication
viewExportConfiguration
File: Jenkins.groovy
View Export Jenkins configuration
Parameters:
  • jenkinsUrl: (String) The URL of the Jenkins instance
  • jenkinsApiKey: (String) The API key for authentication
safeRestart
File: Jenkins.groovy
Safe restart Jenkins
Parameters:
  • jenkinsUrl: (String) The URL of the Jenkins instance
  • jenkinsApiKey: (String) The API key for authentication

ParameterStore

ParameterStore
File: ParameterStore.groovy
A utility to interact with AWS Systems Manager Parameter Store.
Parameters:
  • script: (reference) The script context to execute shell commands.
getParameter
File: ParameterStore.groovy
Retrieves a parameter from AWS Systems Manager Parameter Store.
Parameters:
  • parameterPath: (String) The name of the parameter to retrieve.
  • parameterQuery: (String) The specific attribute of the parameter to query (default: 'Parameter.Value').
  • region: (String) The AWS region where the parameter is stored (default: region from CommonConstants).
Returns: parameter (String) The value of the specified parameter as a string.
putParameter
File: ParameterStore.groovy
Updates or creates a parameter in AWS Systems Manager Parameter Store.
Parameters:
  • parameterPath: (String) The name of the parameter to update or create.
  • parameterValue: (String) The value to store in the parameter.
  • type: (String) The type of the parameter (default: 'SecureString').
  • region: (String) The AWS region where the parameter is stored (default: region from CommonConstants).

ReleaseUtils

ReleaseUtils
File: ReleaseUtils.groovy
Utility class for handling release tasks
Parameters:
  • script: The Jenkins script object
getBumpType
File: ReleaseUtils.groovy
Get the bump type for the release
Returns: (String) The bump type
bumpVersion
File: ReleaseUtils.groovy
Bump the version for the release
Parameters:
  • version: (String) The current version
  • bumpType: (String) The bump type
Returns: (String) The new version
writeChangelog
File: ReleaseUtils.groovy
Write the changelog for the release
Parameters:
  • version: (String) The current version

Route53

Route53
File: Route53.groovy
A utility to interact with AWS Route53.
Parameters:
  • script: (Object) The script context to execute shell commands.
  • hostedZoneId: (String) The AWS Route53 hosted zone ID.
  • region: (String) The AWS region. Default is from CommonConstants.
modifyRecord
File: Route53.groovy
Creates or updates a single DNS record in Route53.
Parameters:
  • recordName: (String) The name of the DNS record
  • recordType: (String) The type of DNS record (e.g., "CNAME", "A", "TXT")
  • recordValue: (String) The value/content of the DNS record
  • ttl: (Integer) Optional. Time to live for the record. Default is 300.
  • action: (String) Optional. The action to perform ("UPSERT", "CREATE", "DELETE").
Returns: (String) The response from the AWS CLI command
Example:
def route53 = new Route53(this, "Z123456789", "us-east-1")
route53.modifyRecord("subdomain.example.com", "CNAME", "target.example.com", 300)
batchUpsertRecords
File: Route53.groovy
Creates or updates multiple DNS records in Route53 with a single batch operation.
Parameters:
  • records: (List<Map>) List of DNS records to create/update. Each record should have:
Returns: (String) The response from the AWS CLI command
Example:
def route53 = new Route53(this, "Z123456789", "us-east-1")
def records = [
[name: "*.example.com", type: "CNAME", value: "target1.example.com", ttl: 300],
[name: "_acme-challenge.example.com", type: "CNAME", value: "validation.example.com", ttl: 300]
]
route53.batchUpsertRecords(records)
deleteRecord
File: Route53.groovy
Deletes a DNS record from Route53.
Parameters:
  • recordName: (String) The name of the DNS record to delete
  • recordType: (String) The type of DNS record
  • recordValue: (String) The value of the DNS record to delete
  • ttl: (Integer) Optional. TTL of the record to delete. Default is 300.
Returns: (String) The response from the AWS CLI command

S3

uploadFile
File: S3.groovy
A utility to interact with AWS S3.
Parameters:
  • localFilePath: (String) The path where the file is located.
  • bucket: (String) The name of the S3 bucket to push the files to.
  • s3Path: (String) The path where to upload the file in the given S3 bucket.
  • region: (String) The AWS region where the S3 bucket is located (default: region from CommonConstants).
downloadFile
File: S3.groovy
Downloads a given file from an S3 bucket
Parameters:
  • s3Path: (String) The path where to the file is located in the given S3 bucket.
  • bucket: (String) The name of the S3 bucket to retrieve the files from.
  • localFilePath: (String) The path where to download the files.
  • region: (String) The AWS region where the S3 bucket is located (default: region from CommonConstants).
getPreSignedUrl
File: S3.groovy
Check if a file or folder exists in a S3 bucket
Parameters:
  • fileOrFolder: (String) The path where the file is located.
  • s3Path: (String) The path where the file is in the given S3 bucket.
  • bucket: (String) The name of the S3 bucket.
  • region: (String) The AWS region where the S3 bucket is located (default: region from CommonConstants).
  • s3Path: (String) The path where the file is located in the given S3 bucket.
  • bucket: (String) The name of the S3 bucket to retrieve the files from.
  • expiry: (int) The expiry time for the pre-signed URL (default: 3600 seconds).
  • region: (String) The AWS region where the S3 bucket is located (default: region from CommonConstants).

SecretManager

fetchSecrets
File: SecretManager.groovy
A utility to interact with AWS Secrets Manager.
Parameters:
  • secretName: (String) The name of the secret to fetch.
  • region: (String) The AWS region where the secret is located (default: region from CommonConstants).
Returns: (String) The secret value in JSON format

Security

Security
File: Security.groovy
Security related functions for scanning and analyzing Docker images and code
Parameters:
  • script: (Script) The Jenkins script object
trivyScan
File: Security.groovy
Perform Trivy security scan on a Docker image and generate reports
Parameters:
  • repo: (String) The docker repository to scan
  • outputPath: (String) path to save the HTML report.
  • tag: (String) The tag of the image to scan. Default: 'latest'