Jenkins helm installation does not remove plugins - jenkins

I perform an installation og jenkins on GKE, using the official helm chart.
I initially pass a list of plugins to the corresponding key
- plugin1
- plugin2
- plugin3
- plugin4
and perform helm upgrade --recreate-pods --force --tls --install
I then take out some of the plugins from the above list and run the same helm command again, e,g, with
- plugin1
- plugin2
However jenkins keeps all the plugins from the initial list.
Is this the expected behavior?

Yes, it is an expected behavior.
To change this behavior you should set the parameter master.overwritePlugins to true.
Example:
helm upgrade --set master.overwritePlugins=true --recreate-pods --force --install
From Helm chart documentation:
| master.overwritePlugins | Overwrite installed plugins on start. | false |

Related

gcloud - command not found in Jenkins

I am trying to build a pipeline with gcloud commands to create cluster, deploy apps, etc. but couldn't do it as getting the error gcloud - command not found
Tried to refer some SO links but no luck. I can see the GCloud SDK plug-in was installed in my Jenkins instance as shown below, and tried to set the Environment variable and directly passing like below too..
withEnv(['GCLOUD_PATH=/var/lib/jenkins/plugins/gcloud-sdk/']) {
sh '$GCLOUD_PATH/gcloud --version'
}
still command not found error. Not sure what I am doing wrong or missing any. Appreciate any inputs on this.

Helm Set Docker Image Tag Dynamically

I am pushing Docker images to our private registry via Jenkins with the following command:
def dockerImage = docker.build("repo/myapp:${env.BUILD_NUMBER}")
(BUILD_NUMBER increases after every build.)
Because I am new to using Helm, I could not decide how should I give the tag for images in values.yaml.
I would like to deploy my app to multiple environments such as:
dev
test
prod
Let's say I was able to deploy my app via Helm to dev, and the latest BUILD_NUMBER is:
100 for dev
101 for test
102 for prod
What should be the tag value, then?
image:
repository: registryt/myrepo/image
tag:
You should put "some" tag into your values.yaml which will act as the default tag. Each Helm Chart has it, you can check the official Helm Charts here.
Now, you have two options on how to act with the different environments.
Option 1: Command line parameters
While installing your Helm Chart, you can specify the tag name dynamically with --set. For example:
$ helm install --set image.tag=12345 <your-chart-name>
Option 2: Separate values.yaml files
You can store separate values.yaml in your repository, like:
values.dev.yaml
values.prod.yaml
Then, update the correct values in your Jenkins pipeline.
I just ran into this issue with GitHub Actions. As the other answer already noted, set the image.tag in values.yaml to something as a default. I use latest as the default.
The problem is that the helm upgrade command only upgrades if the image tag is different. So "latest" isn't unique enough for Helm to do the rolling update. I use a SHA in GitHub Actions as my unique version tag. You could tag the image like this:
def dockerImage = docker.build("repo/myapp:${env.NAME}-${env.BUILD_NUMBER}")
Then in your helm command just add a --set:
helm upgrade <helm-app> <helm-chart> --set image.tag=${env.NAME}-${env.BUILD_NUMBER}
This command will override whatever value is in values.yaml. Keep in mind that the --set value must follow the structure of your values.yaml so in this case image is a top level object, with a property named tag:
values.yaml
image
name
tag
pullPolicy
port
replicaCount
May be its late, but hope helps someone later with this similar query.
I had similar situation and was looking for some options. It was painful as helm3 package doesn't come with --set option, which exists in version 2.
Solution:
Implemented with Python jinja packages, along with environment variables, with below steps.
Create values.yaml.j2 file inside your chart directory, with your values file along with templates as per below.
name: {{ APPLICATION | default("SampleApp") }}
labelname: {{ APPLICATION | default("SampleApp") }}
image:
imageRepo: "SampleApp"
imageTag: {{ APPLICATION_IMAGE_TAG | default("1.0.27") }}
Dependency packages (in container):
sh 'yum -y install python3'
sh 'yum -y install python3-pip'
sh 'yum -y install python-setuptools'
sh 'python3 -m pip install jinja-cli'
Sample Environment Variables In your Build Pipeline:
APPLICATION= "AppName"
APPLICATION_VERSION= '1.0'
APPLICATION_CHART_VERSION= '1.0'
APPLICATION_IMAGE_TAG= "1.0.${env.BUILD_NUMBER}"
Now in your pipeline, before packaging chart, Apply/Replace the templates with one jinja command as like below.
sh "jinja CHART_DIR/values.yaml.j2 -X APP.* -o CHART_DIR/values.yaml"
helm package CHART_DIR
Done!

Jenkins and Gradle : Unable to get environment variables

This is my gradle script,
String home = "${System.env.FALIB_HOME}"
task doit{
println home
}
On running,
gradle doit
through command prompt Im getting,
D:\ThirdPartyJars
:doit UP-TO-DATE
BUILD SUCCESSFUL
Same command run through Jenkins is giving
null
:doit UP-TO-DATE
BUILD SUCCESSFUL
How to get value instead of null?
I'm using,
Gradle version 2.9
Jenkins version 2.32.2
Gradle plugin in Jenkins version 1.25
I may be because your jenkins user actually has no home.
run this command:
sudo cat /etc/passwd | grep jenkins (or whatever your jenkins user is)
it's a colon seperated list but look at the last 2 : entries. They are: /home/dir:/path/to/login/shell if you have ::/bin/nologin or something like that, there is your answer. If there is a home defined here, make sure it actually exists - if the dir doesn't exist your home will be /

Jenkins build Docker raise error Unrecognized field "ExecDriver"

I'm integrating Docker with Jenkins, but the build is showing the following error
VERSIONS
- Jenkins version 1.555
- Docker version 0.9.0
Jenkins Plugins
- Mercurial (to pull code from bitbucket)
- Docker (docker-plugin)
- docker-build-step
[Docker] INFO: created container id e463f956d2d4.... (from image my-base)
FATAL: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "ExecDriver"
docker-build-step
I assume that the Docker plugin for Jenkins is very strict about what it expects, and when Docker 0.9 returns an ExecDriver value (for instance, in docker inspect) it gets confused.
The easiest fix is, as you did, roll back to 0.8; but it would be better to fix the Jenkins module; either by using semver (Docker API is versioned) or by making the code accept the ExecDriver attribute optionally.

How do I use the CloudBees SDK (command line interface) on Jenkins

I am running a job in DEV#cloud on cloudbees - but I want to use the CloudBees SDK/CLI, how do I do this from within the job?
The Scripting Bees SDK in Jenkins doc includes a good write-up about this.
Firstly, you use a freestyle job, then install the Bees SDK as part of it:
# INSTALL AND CONFIGURE BEES SDK
export BEES_HOME=/opt/cloudbees/cloudbees-sdk/
export PATH=$PATH:$BEES_HOME
if [ ! -d ~/.bees ]; then
bees init -f -a <your account name here> -ep us -k $BEES_API -s $BEES_SECRET
fi
Then set the secrets in your Jenkins setup for BEES_API BEES_SECRET - and then you can use bees SDK commands.
You can install any plugins you need from here as well.

Resources