Cannot run a Groovy sh command in Jenkins

I cannot run Groovy scripts in Jenkins. Let me give you an overview of my setup.

I cannot run Groovy scripts in Jenkins. Let me give you an overview of my setup.

I run the official Jenkins docker image with the follow docker compose:

version: '2'
services:
  jenkins:
    image: jenkins/jenkins:lts
    container_name: jenkins
    ports:
      - 8080:8080
    volumes:
      - ./home:/var/jenkins_home

Jenkins is up & running as it should. I installed also the Groovy plugin http://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin .

Now I tried to run a simple Groovy script like this:

LSOUT = sh (
    script: 'ls -al',
    returnStdout: true
).trim()
echo "${LSOUT}"

But I cannot make it working. This is the error I am getting:

Building in workspace /var/jenkins_home/workspace/test_groovy
[test_groovy] $ groovy /var/jenkins_home/workspace/test_groovy/hudson4423271822305767083.groovy
Caught: groovy.lang.MissingMethodException: No signature of method: hudson4423271822305767083.sh() is applicable for argument types: (java.util.LinkedHashMap) values: [[script:ls -al, returnStdout:true]]
Possible solutions: use([Ljava.lang.Object;), is(java.lang.Object), run(), run(), any(), use(java.util.List, groovy.lang.Closure)
groovy.lang.MissingMethodException: No signature of method: hudson4423271822305767083.sh() is applicable for argument types: (java.util.LinkedHashMap) values: [[script:ls -al, returnStdout:true]]
Possible solutions: use([Ljava.lang.Object;), is(java.lang.Object), run(), run(), any(), use(java.util.List, groovy.lang.Closure)
    at hudson4423271822305767083.run(hudson4423271822305767083.groovy:1)
Build step 'Execute Groovy script' marked build as failure
Finished: FAILURE

Groovy is also installed as package in the container. Any idea?

WordPress in Docker. Part 1: Dockerization

WordPress in Docker. Part 1: Dockerization

This entry-level guide will tell you why and how to Dockerize your WordPress projects.

This entry-level guide will tell you why and how to Dockerize your WordPress projects.

Docker Tutorial for Beginners - Learn Docker in 2020

Docker Tutorial for Beginners - Learn Docker in 2020

In this course you will learn Docker through a series of lectures that use animation, illustration and some fun analogies that simply complex concepts, we have demos that will show how to install and get started with Docker and most importantly we have hands-on labs that you can access right in your browser.

In this course you will learn Docker through a series of lectures that use animation, illustration and some fun analogies that simply complex concepts, we have demos that will show how to install and get started with Docker and most importantly we have hands-on labs that you can access right in your browser.

In this tutorial, you will learn:

  1. What is Docker ?
  2. How DOCKER works | Docker Architecture
  3. Benefits of DOCKER | Why to use DOCKER | Advantages of DOCKER
  4. How to install DOCKER on LINUX ? Step by Step
  5. How to install DOCKER on WINDOWS ? Step by Step
  6. How to install DOCKER on MAC ? Step by Step | How to Install Docker
  7. Docker FAQ | Docker Interview Questions | Docker for Beginners
  8. What are Docker Images | How to run Docker Images | Docker Images Beginner Tutorial
  9. What are Docker Containers | How to create Docker Containers | Basic Commands
  10. How to run Jenkins on Docker container | How to create Jenkins Volumes on Docker | Beginners
  11. What is Dockerfile | How to create and build Dockerfile | Dockerfile Basic Commands
  12. What is Docker Compose | How to create docker compose file | How to use Compose
  13. What is Docker Volume | How to create Volumes | What is Bind Mount | Docker Storage
1. What is Docker ?

Docker is the world’s leading software container platform
Docker makes the process of application deployment very easy and efficient and resolves a lot of issues related to deploying applications

Docker is a tool designed to make it easier to deploy and run applications by using containers

Docker gives you a standard way of packaging your application with all its dependencies in a container

Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

Understand Docker with analogy of the Shipping industry

How a real world problem was resolved using containers

2. How DOCKER works | Docker Architecture
  • How Docker works ?
  • Understand a general workflow of docker
  • Difference between virtualization and containerization
  • Understand docker client server architecture
  • Understand:
  • Docker file
  • Docker images
  • Docker Containers
  • Docker Hub / Registry
  • Docker client
  • Docker server / daemon
  • Docker engine
3. Benefits of DOCKER | Why to use DOCKER | Advantages of DOCKER
  • Benefits of using Docker
  • Build app only once
  • No worries that the application will not perform the same way it did on testing env
  • Portability
  • Version Control
  • Isolation
  • Productivity
  • Docker simplifies
  • DevOps
4. How to install DOCKER on LINUX ? Step by Step 5. How to install DOCKER on WINDOWS ? Step by Step 6. How to install DOCKER on MAC ? Step by Step | How to Install Docker 7. Docker FAQ | Docker Interview Questions | Docker for Beginners 8. What are Docker Images | How to run Docker Images | Docker Images Beginner Tutorial
  • What are images
  • How to pull image
  • How to run a container using an image
  • Basic Commands
9. What are Docker Containers | How to create Docker Containers | Basic Commands
  • What are Containers
  • How to create Containers
  • How to start / stop Containers
  • Basic Commands
10. How to run Jenkins on Docker container | How to create Jenkins Volumes on Docker | Beginners
  1. How to start Jenkins on Docker Container
  2. Start and Stop Jenkins Container
  3. How to set Jenkins home on Docker Volume and Host Machine
    : docker pull jenkins
    : docker run -p 8080:8080 -p 50000:50000 jenkins
    : docker run --name MyJenkins -p 8080:8080 -p 50000:50000 -v /Users/raghav/Desktop/Jenkins_Home:/var/jenkins_home jenkins
    : docker run --name MyJenkins2 -p 9090:8080 -p 50000:50000 -v /Users/raghav/Desktop/Jenkins_Home:/var/jenkins_home jenkins
    : docker volume create myjenkins
    : docker volume ls
    : docker volume inspect myjenkins
    : docker run --name MyJenkins3 -p 9090:8080 -p 50000:50000 -v myjenkins:/var/jenkins_home jenkins
    : docker inspect MyJenkins3
    In case you face issues like installing plugins on this Jenkins, can setup jenkins with this command:
    $ docker run -u root --rm -p 8080:8080 -v /srv/jenkins-data:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock --name jenkins jenkinsci/blueocean
11. What is Dockerfile | How to create and build Dockerfile | Dockerfile Basic Commands
  1. What is Dockerfile
  2. How to create Dockerfile
  3. How to build image from Dockerfile
  4. Basic Commands
12. What is Docker Compose | How to create docker compose file | How to use Compose
  1. What | Why - Docker Compose
  2. How to install
  3. How to create docker compose file
  4. How to use docker compose file to create services
  5. Basic Commands
13. What is Docker Volume | How to create Volumes | What is Bind Mount | Docker Storage
  1. What are Volumes
  2. How to create / list / delete volumes
  3. How to attach volume to a container
  4. How to share volume among containers
  5. What are bind mounts
    Volumes are the preferred mechanism for persisting data generated by and used by Docker containers
    : docker volume //get information
    : docker volume create
    : docker volume ls
    : docker volume inspect
    : docker volume rm
    : docker volume prune

What is Docker | Docker Tutorial for Beginners

What is Docker | Docker Tutorial for Beginners

This DevOps Docker Tutorial on what is docker will help you understand how to use Docker Hub, Docker Images, Docker Container & Docker Compose. This tutorial explains Docker's working Architecture and Docker Engine in detail.

This Docker tutorial also includes a Hands-On session around Docker by the end of which you will learn to pull a centos Docker Image and spin your own Docker Container. You will also see how to launch multiple docker containers using Docker Compose. Finally, it will also tell you the role Docker plays in the DevOps life-cycle.

The Hands-On session is performed on an Ubuntu-64bit machine in which Docker is installed.