Jenkins shared library in groovy for deploying, restarting and wait for AWS ECS using jenkins pipeline.
awscli and jq must be installed on the host system
pip install awscli
apt-get install jq
Below is the step by step examples that tell you how to get it working
Manage Jenkins -> Configure System
* Scroll down to Global Pipeline Libraries section in cofiguration options.
* Click on Add button.
* Name the library (e.g. ecs-jenkins-lib)
* Set a default version (we can also specify this while importing library in pipeline)
* Now select the Modern SCM in Retrieval method section
* Select the Github option from Source Code Management section
* Now specify the github account and repository details
* Credentials (any github user credential, required because github has pull request limits for
annonymous users.
* Specify owner as vikramjakhr
* Select the ecs-jenkins-lib from the dropdown
* Leave remaining options as it is.
Currently library has 3 features: deploy, restart and wait
This method deploys a new task definition to the specified service in a cluster.
Signature of the deploy method
def deploy(cluster, service, task_family, image, region, boolean is_wait = true, String awscli = "aws") {
...
}
Pipeline example:
// Import at the top in pipeline code as:
@Library('ecs-jenkins-lib@v1.0.0') _
// sample pipeline stage code
stage('Deploy') {
steps {
script {
ecs.deploy("${env.CLUSTER_NAME}", "${env.SERVICE_NAME}", "${env.TASK_FAMILY}", "${env.IMAGE_TO_DEPLOY}", "${env.REGION}", true)
}
}
}
This method restart(redeploy) the containers in the specified service in a cluster.
Signature of the restart method
def restart(cluster, service, region, String awscli = "aws") {
...
}
Pipeline example:
// Import at the top in pipeline code as:
@Library('ecs-jenkins-lib@v1.0.0') _
// sample pipeline stage code
stage('Restart') {
steps {
script {
ecs.restart("${env.CLUSTER_NAME}", "${env.SERVICE_NAME}", "${env.REGION}")
}
}
}
This method waits for until running count matches the desired count for a service.
Signature of the wait method
def wait(cluster, service, region, String awscli = "aws") {
...
}
Pipeline example:
// Import at the top in pipeline code as:
@Library('ecs-jenkins-lib@v1.0.0') _
// sample pipeline stage code
stage('Wait') {
steps {
script {
ecs.wait("${env.CLUSTER_NAME}", "${env.SERVICE_NAME}", "${env.REGION}")
}
}
}
You are welcome to contribute!
For the versions available, see the tags on this repository.
- Vikram Jakhar - Initial work - vikramjakhr