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

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

Related

unable to use zsh/bash in Jenkins Execute Shell

I am trying to run iOS builds in a remote Mac mini connected as an agent to Jenkins master running on Linux server. I have all the dependencies installed and env variables set up via .zshrc(zsh is the default shell in catalina and above).
When I run scripts(npm install, pod install and so on) through Execute Shell option in Jenkins Freestyle project, it throws npm command not found/ pod command not found. Even when I shebang with /bin/zsh at the start of script, it doesn't work.
Is there a way to switch shell to zsh/bash or import all configurations into sh in the jenkins build process?
Jenkins leverage the 'rc' file when it connects to the slave (via ssh) and load the env variable (This also means when you will change anything in the rc file you need to disconnect and reconnect the slave to load the changes). Now it depends on the default SHELL set for the User you used to connect the slave. You need to check that and align the env variable accordingly in the right rc file.
In the current situation, if you don't want to change anything you could also do a
source ~/.zshrc
at the start of your script. This will load the env vars defined in that file
One more way is to set the env variable for a node is under "Node Properties" in node configuration.

Unable to determine what the withEnv is doing in Jenkinsfile

I have just started writing Jenkinsfile. I was viewing the following two URLs to learn how to build a Java application, push it to Nexus and then invoke Ansible to deploy.
Redhat Jenkinsfile description
Actual Jenkinsfile
In the second link the following is mentioned several times whose function I am unable to understand:
withEnv(["PATH+MAVEN=${tool 'm3'}/bin"])
What I can find from net is that withEnv is used to create/override a environment variables. But what is ${tool 'm3'}/bin doing? Normally the syntax of withEnv is VARIABLE_NAME=value/expression.
The ${} is substituting a command/variable into the GString. See groovy docs on string Interpolation
From the looks of it, it would be safe to assume tool 'm3' is returning the install path which then gets /bin appended.
So the end result would be
PATH+MAVEN=/my/path/to/m3/etc/bin
Additionally to #metalisticpain's answer, there's some background configuration to the tools directive on the Jenkins server itself that configures the installation paths to be used.
Let's say you have jdk-1.8.0 installed as a tool name on the Jenkins server, then it can be used in the Jenkinsfile as such in your example:
withEnv(["PATH+JDK=${tool 'jdk-1.8.0'}/bin"])
Taken from the documentation linked above:
The tool name must be pre-configured in Jenkins under Manage Jenkins → Global Tool → Configuration.

jenkins pipeline DOCKER_HOST

I need to run a docker-container inside my pipeline.
My problem is, there is no docker.sock available inside the Jenkins-container. And actual no chance to get it.
But I found some jobs using docker with this Option:
"Inject environment variables to the build process" -> "Properties
Content"
And following configured:
DOCKER_HOST=tcp://<ip>:<port>
DOCKER_CERT_PATH=/var/jenkins_home/certs
In my understanding, this is equivalent to the docker.sock and useable as plugin, isnt it?
But how can i use it inside a (multi-)pipeline project?
I've tried using this Block inside my Note:
environment {
DOCKER_HOST = 'tcp://<ip>:<port>'
DOCKER_CERT_PATH = '/var/jenkins_home/certs'
}
But got same issue: "docker: not found"
I might have a logical fallacy. Hope someone could help.
Otherwise is it possible to create a jenkins-slave including a docker.sock?
But got same issue: "docker: not found"
This indicates that your Jenkins slave, the one running the pipeline script, does not have the docker command line tools. This depends on your distribution, but in my case I fixed it by changing my build-slave/pipeline-runner creation steps to include:
yum install -y docker-client
Note that you'll still need that for the Cloudbees docker plugin (the thing which provides stuff like docker.build() and docker.image()) because it translates those nice pipeline directives down into shell commands.

Jenkins: Slave selection based on user's choice

I'm trying to configure a jenkins job so that based on the choice of the user the node/slave should be selected.
example : if choice = windows ->slave1
if choice = Linux ->slave2
I've tried with configuration matrix i'm getting error that the nodes are offline.Is there any plugin to do such selections in jenkins
The simplest is to create two build jobs that are then tagged to a specific slave.
When you configure the job you can add labels to it that specify the requirements for this job.
Example:
linux-build, add the label linux
windows-build: add the label windows
Then, when you create the slaves you need to assign them labels as well specifying the capabilities.
Example:
Windows system, add the windows label
Linux system, add the linux label
After this your builds will automatically go to the correct system and you never have to specify anything again. This is better then having to manually specify and trigger a job.
One more advantage, if the job fails you know why.. maybe you linux job always succeeds but you windows job always fails, if you combine this in one job you can't really see this pattern but if you have two separate builds you will immediately see a dark cloud forming over you windows build.
Checkout the following plugin:
https://wiki.jenkins-ci.org/display/JENKINS/NodeLabel+Parameter+Plugin
I used the Jenkins CLI to implement the dynamical slave selection.
1) create two jobs: job A triggers job B
2) at job A, input the followings at Build/Execute Shell
if choice = windows, SERVER=slave1
if choice = Linux, SERVER=slave2
java -jar jenkins-cli.jar -s http_to_jenkins-server:port build buildname -p SERVER_LABEL=$SERVER -v -w --username yourusername --password yourpassword
3) at job B, select "This build is parameterized" and add a String Parameter SERVER.
Hope it helps.

How do I override http_proxy environment variable in Jenkins?

I have the following setup:
Jenkins -> Ant script -> Python script -> Interact with Selenium
I run Jenkins on a windows box. My Jenkins calls an Ant script which calls a python script which interacts with Selenium. The problem I have is that the http_proxy environment variable is defined and points to a proxy, that is intented to access the internet and not my system under test. When I run my Jenkins job I get a error message from the proxy along the lines that he could not access my system under test.
How can I disable the http_proxy in Jenkins so that it won't pass them to Ant -> Python -> Selenium?
Use EnvInject plugin to reset the variable in a build step before you run ANT.
Maybe try setting the variable in the jenkins settings page (override the default), or in the job (as a parameter). Both options will override any existing value on the system. Is this what you need?

Resources