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