Error: org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
Leave a reply
Are you facing the error like below for your Jenkins configuration:
Started by user admin
[Pipeline] Start of Pipeline
[Pipeline] sh
[Pipeline] End of Pipeline
org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
Perhaps you forgot to surround the code with a step that provides this, such as: node
at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:265)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:299)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
If yes, you might want to try to surround the part of code that causing error with
node
step like below:
pipeline {
agent any
parameters {
choice(
name: 'IMAGE_VERSION',
choices: get_image_versions(),
description: 'Select the version of the image to use'
stages {
stage('Build') {
steps {
echo "Building image version ${params.IMAGE_VERSION}"
def get_image_versions() {
node { //Add node here
def registry = 'http://192.168.0.10:5000'
def tags = sh(
script: "curl -s ${registry}/v2/aspnetdocker2/tags/list | jq -r '.tags[]'",
returnStdout: true
).trim().split('\n')
return tags.toList()
The issue occurred due to the part of
sh
command was executed using
admin
user instead of
jenkins
user. Surround with
node
will execute the command using
jenkins
user and the error disappear.
This is just a note for easy reference/search back.
docker exec -it -u root <container_name/container_id> bash
Replace the with actual container name / id. Please note the id can be partially as long as is unique prefix. The name or id using command below.
-u root
is the user you want to use to login.
bash
is the command to execute, so for this is login to Bash. You can replace it with another command you want to execute e.g.
ping google.com
docker ps
It is common for us to have multiple versions of Java/JDK in our Ubuntu Linux namely Java 8, 11 or 17…but how can we change the default Java/JDK version? We can use the
update-alternatives
command inside the Ubuntu.
First thing first, first we must make sure we have multiple versions of JDK inside our Ubuntu machine, we can check using the command below:
apt list --installed *jdk*
Alternatively, you can use
update-alternatives
command too to list out all Java inside your machine.
update-alternatives --list java
After confirmed we have multiple versions of Java, we can run the
update-alternatives --config
command. For e.g. to update Java version, we use the command below:
sudo update-alternatives --config java
It will list out options for you to choose like below. The * beside 1 mean current choice, and you have 0 to 3 options to choose. For this example, 0 had been selected. The
update-alternatives
will then update the symbolic links determining default Java command.
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 auto mode
* 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode
3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
update-alternatives: using /usr/lib/jvm/java-17-openjdk-amd64/bin/java to provide /usr/bin/java (java) in auto mode
Please note the command above only update
java
command. You still have other commands that need to update accordingly. You can find most of the commands in
/usr/lib/jvm/java-17-openjdk-amd64/bin/
folder. For e.g. in this scenario, the folder has the command below:
ls /usr/lib/jvm/java-17-openjdk-amd64/bin/
jar javac jcmd jdeprscan jhsdb jlink jpackage jshell jstatd serialver
jarsigner javadoc jconsole jdeps jimage jmap jps jstack keytool
java javap jdb jfr jinfo jmod jrunscript jstat rmiregistry
You might do not need to update them all since it depends on your usage, but it is quite common to update
java, jar, javac, javadoc
. The commands will be like below:
sudo update-alternatives --config jar
sudo update-alternatives --config javac
sudo update-alternatives --config javadoc
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here:
Cookie Policy