-
Go to Manage Jenkins > Configure System.
-
Scroll to Global Pipeline Libraries.
-
Add a new library with:
-
Name:
jenkins-shared-lib(or your preferred name) -
Source Code Management: Git
-
Project Repository: https://github.com/singhragvendra503/Jenkins-shared-library.git
-
Default version:
masteror whichever branch you use -
Load implicitly: (optional)
-
-
There are five shared library functions.
- branchBaseBuildDeployECS In this function six stages are there
Git Checkout,ECR Login,Docker Build,Docker Push,Deploy to ECS,Cleanup.
@Library('jenkins-shared-lib') _ // Name configured in Jenkins > Global Pipeline Libraries branchBaseBuildDeployECS( agentLabel: 'docker-builder', // Optional if your shared lib supports it bitbucketRepoUrl: 'https://github.com/singhragvendra503/myapplication-service.git', ecrRegistry: '112233445566.dkr.ecr.ap-south-1.amazonaws.com', imageName: 'myapplication-service', imageTag: 'prod', // Optional if handled internally clusterName: 'my-production-cluster', serviceName: 'prod-myapplication-service' )
- branchBaseBuildECS In this function five stages are there
Git Checkout,ECR Login,Docker Build,Docker Push,Cleanup.
@Library('jenkins-shared-lib') _ // Name configured in Jenkins > Global Pipeline Libraries branchBaseBuildDeployECS( agentLabel: 'docker-builder', // Optional if your shared lib supports it bitbucketRepoUrl: 'https://github.com/singhragvendra503/myapplication-service.git', ecrRegistry: '112233445566.dkr.ecr.ap-south-1.amazonaws.com', imageName: 'myapplication-service', imageTag: 'prod' )
- tagBaseBuildDeployECS Similer as
branchBaseBuildDeployECS
@Library('jenkins-shared-lib') _ // Name configured in Jenkins > Global Pipeline Libraries branchBaseBuildDeployECS( agentLabel: 'docker-builder', // Optional if your shared lib supports it bitbucketRepoUrl: 'https://github.com/singhragvendra503/myapplication-service.git', ecrRegistry: '112233445566.dkr.ecr.ap-south-1.amazonaws.com', imageName: 'myapplication-service', imageTag: 'prod', // Optional if handled internally clusterName: 'my-production-cluster', serviceName: 'prod-myapplication-service' )
- tagBaseBuildECS Similer as
branchBaseBuildECS
@Library('jenkins-shared-lib') _ // Name configured in Jenkins > Global Pipeline Libraries branchBaseBuildDeployECS( agentLabel: 'docker-builder', // Optional if your shared lib supports it bitbucketRepoUrl: 'https://github.com/singhragvendra503/myapplication-service.git', ecrRegistry: '112233445566.dkr.ecr.ap-south-1.amazonaws.com', imageName: 'myapplication-service', imageTag: 'prod' )
- branchBaseBuildDeployECSWithGradle6.5Tool Similer as
branchBaseBuildDeployECS,Gradle Buildbut using gradle 6.5.
@Library('jenkins-shared-lib') _ branchBaseBuildDeployECS( agentLabel: 'docker-builder', bitbucketRepoUrl: 'https://github.com/singhragvendra503/myapplication-service.git', ecrRegistry: '112233445566.dkr.ecr.ap-south-1.amazonaws.com', imageName: 'myapplication-service', imageTag: 'prod', clusterName: 'my-production-cluster', serviceName: 'prod-myapplication-service', mavenTool: 'Maven 3.8.6' )
- branchBaseBuildDeployECS In this function six stages are there
These tools currently in use
tools {
gradle 'Gradle6.5'
}Note:- You can make these shared library more dynamic like pass Dockerfile name if you are using different file for different environments.