How to set hudson.slaves.NodeProvisioner.initialDelay in Jenkins kubernetes plugin - jenkins

I get the attribute of hudson.slaves.NodeProvisioner.initialDelay in Jenkins kubernetes plugin from Jenkins API,but I don't know How to set hudson.slaves.NodeProvisioner.initialDelay with user interface.

You can't set it from the UI, you have to start Jenkins with that Java
system property
-Dhudson.slaves.NodeProvisioner.initialDelay=0

If you have deployed Jenkins on Kubernetes itself,
You can set this under env var JAVA_OPTS in your Kubernetes YAML file like :
env:
- name: JAVA_OPTS
value: "-Dhudson.slaves.NodeProvisioner.initialDelay=0 -Dhudson.slaves.NodeProvisioner.MARGIN=50 -Dhudson.slaves.NodeProvisioner.MARGIN0=0.85"
You can find such YAML file at Jenkins Kubernete Plugin's Github repo itself.

Related

Jenkins not updating the K8S agent definition

We have our Jenkins configured with the Kubernetes agent, defined in a yaml file. The problem is that when I try to update the yaml, Jenkins doesn't see the update and still uses the old agent template (some cache'ing?).
Job's build configuration:
Jenkinsfile-gke.groovy with the updated yaml file
pipeline {
agent {
kubernetes {
yamlFile '.jenkins/agent-pod.yaml'
...
Build's logs (the files are being obtained from the correct commit that is updating them, however the logs beneath show that the version before the chasnges is being applied):

How do I access a variable defined in my jenkins pipeline with gatsby?

I have a Gatsby project that is integrated with a jenkins CI/CD pipeline. I define a variable in the jenkins pipeline like so:
environment {
my_env = "${env.GIT_BRANCH"
}
I have pipelines that run from the dev and master branches of the repo hosting my Gatsby project. I want to use this variable in my Gatsby config file so that when I run a pipeline gatsby will pull content from either the dev or master environments of the CMS I'm using.
The problem is Gatsby seems only able to read environment variables from .env files out of the box. I am not sure how to get it to read variable from something that's not a .env but also stored in the root (in this case, a jenkinsfile). Is there any workaround for this?
If you set your enviornment variable in jenkinsfile,and using the same agent , then you can just access that variable using env..
environment {
MY_ENV_VAR="myvalue"
}
// you can access using:
env.MY_ENV_VAR

configure ci_secrets for Jenkins ci

ci_secrets is (https://github.com/pmarlow/ci_secrets) is a repo secret scanning tool which can easily be integrated with Travis and Gitlab ci without a need for a persistent server.
Configuring this into the Jenkins pipeline is a bit tricky though as Jenkins does not support the environment variables like
"TRAVIS_COMMIT_RANGE" and/or
which is required to determine the latest-scanned commit from the first commit in the range.
is there a way to implement this in a Jenkins pipeline?
for example:
script:
- export COMMIT_RANGE=${TRAVIS_COMMIT_RANGE:-"000000000000000000000000000000000000"}
- export LAST_COMMIT=${COMMIT_RANGE%%.*}
- ci_secrets --since $LAST_COMMIT --includeMergeCommit --log INFO

How to add ca.crt ie certificate inside the docker executor of gitlab runner?

I want to add certificate in docker executor of my gitlab runner. I am facing various issues while doing this.
Can someone help me with how to do it?
If you want to put a file on the gitlab runners and don't want to put that file into your repository e.g. for security reasons:
You can use environment variables for that.
You can set these in the gitlab GUI (Settings --> CI / CD --> Environment Variables)
Copy the content of ca.crt and set it as a value for an environment variable. You can then use that environment variable inside your pipeline file to write the content into a file ca.crt which you can create during the pipeline and put it where it is needed. After creating the environment variable in gitlab you may use it like the following inside the pipeline file:
- echo "$ENVIRONMENT_VARIABLE_NAME" > /path/where/you/want/to/put/ca.crt

Where to set -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=300

I am getting errors from the durable task plugin when I run my pipeline dsl jenkins job.
The error message suggests that I should use:
-Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=300
This is the error I get:
\workspace\ne-sw-manifest_master-5ZF5EWBP7EVBXEBF6AS3C6UQLIXLCS3HRKYND6TPQAPIKZPFBDLQ#tmp\durable-252b3bfd
(JENKINS-48300: if on a laggy filesystem, consider -Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=300)
I am not sure where to set this property.
I tried on Jenkins master -> Configure system -> Global properties -> Environment variables:
Name:org.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL
Value:300
But, I am not sure if this is the right place to add this property OR if it has come into effect.
Also, I haven't restarted the master or slave.
My jenkins set-up is Linux master (Jenkins ver. 2.107.1) and Linux and Windows Slaves.
My build is on a Windows slave (physical machine)
option 1:
Add in your pipeline
script {
System.setProperty("org.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL", "3800");
}
after Running the approve the script in security settings at Manage Jenkins – In-process Script approval.
Option 2:
go to Manage Jenkins -> Script Console
and run
System.setProperty("org.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL", "3800");
This CloudBees article explains how to set Jenkins Java arguments.
Note: you'll need to restart your Jenkins instance.
Edit: As per sirch's comment, I'm copying here the instructions for RedHat and Debian distro's.
Debian / Ubuntu based Linux distributions
If your configuration file is under /etc/default/ look for the argument JAVA_ARGS. It should look something like this:
JAVA_ARGS="-Djava.awt.headless=true"
Then, add the arguments:
JAVA_ARGS="-Xmx2048m -XX:MaxPermSize=512m -Djava.awt.headless=true"
RedHat Linux based distributions
If your configuration file is under /etc/sysconfig/ look for the argument JENKINS_JAVA_OPTIONS. It should look something like this:
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true"
Then, add the arguments:
JENKINS_JAVA_OPTIONS="-Xmx2048m -XX:MaxPermSize=512m -Djava.awt.headless=true"
set it either
JAVA_OPTS
or
JNLP_PROTOCOL_OPTS
which will be included in jenkins slave Startup Options

Resources