patternkubernetesMinor
Deploy helm chart from Jenkins to Kubernetes
Viewed 0 times
chartjenkinskubernetesdeployhelmfrom
Problem
I want to deploy helm chart from Jenkins to Kubernetes but I don't find any Plugins in Jenkins for Helm.
How can I tell Jenkins to run Helm chart in Kubernetes ?
How can I tell Jenkins to run Helm chart in Kubernetes ?
Solution
Use a docker image within your pipeline that has
To quote the docs:
Pipeline is designed to easily use Docker images as the execution
environment for a single Stage or the entire Pipeline. Meaning that a
user can define the tools required for their Pipeline, without having
to manually configure agents. Practically any tool which can be
packaged in a Docker container. can be used with ease by making only
minor edits to a Jenkinsfile.
It then gives an example that we can modify to show running helm:
This is a total game changer. Docker is the plugin to end all plugins. Before Docker you had to find a plug-in written in Java that to exposes a DSL to be scriptable in a Groovy sandbox. That was because it was not secure or scalable to let you simply run your own tools and scripts on a shared Jenkins. You were not even allowed use the full power of Groovy or Java. With Docker it is safe run any script or tools. So you no longer have the indirection of Java plugins and you can use the full power of any Linux tool on any Linux distro.
This approach is exactly how new cloud based build engines work. With bitbucket.com pipelines and cricleci.com you don’t need any plugins. You simply say which containers to use and what commands to run within them just like the example above. The build engine simply checks out the code where the docker container can see it.
Once you have used Docker based builds for a while doing it the old way feels very restricted and limiting. For example consider having to move files around in the build. In a pipeline with Groovy if you are new to Jenkins you have to look at a huge amount of (very ugly) documentation to just to basic things. If you use docker you can simply use standard bash and Linux commands.
helm and other tools installed.To quote the docs:
Pipeline is designed to easily use Docker images as the execution
environment for a single Stage or the entire Pipeline. Meaning that a
user can define the tools required for their Pipeline, without having
to manually configure agents. Practically any tool which can be
packaged in a Docker container. can be used with ease by making only
minor edits to a Jenkinsfile.
It then gives an example that we can modify to show running helm:
pipeline {
agent {
docker { image 'your_image:1.0' }
}
stages {
stage('Deploy') {
steps {
sh 'helm list'
}
}
}
}This is a total game changer. Docker is the plugin to end all plugins. Before Docker you had to find a plug-in written in Java that to exposes a DSL to be scriptable in a Groovy sandbox. That was because it was not secure or scalable to let you simply run your own tools and scripts on a shared Jenkins. You were not even allowed use the full power of Groovy or Java. With Docker it is safe run any script or tools. So you no longer have the indirection of Java plugins and you can use the full power of any Linux tool on any Linux distro.
This approach is exactly how new cloud based build engines work. With bitbucket.com pipelines and cricleci.com you don’t need any plugins. You simply say which containers to use and what commands to run within them just like the example above. The build engine simply checks out the code where the docker container can see it.
Once you have used Docker based builds for a while doing it the old way feels very restricted and limiting. For example consider having to move files around in the build. In a pipeline with Groovy if you are new to Jenkins you have to look at a huge amount of (very ugly) documentation to just to basic things. If you use docker you can simply use standard bash and Linux commands.
Code Snippets
pipeline {
agent {
docker { image 'your_image:1.0' }
}
stages {
stage('Deploy') {
steps {
sh 'helm list'
}
}
}
}Context
StackExchange DevOps Q#5950, answer score: 2
Revisions (0)
No revisions yet.