Cannot run a Groovy sh command in Jenkins

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?

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

WordPress in Docker. Part 1: Dockerization

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

List all containers in Docker(Docker command)

We can get a list of all containers in docker using `docker container list` or `docker ps` commands.

Building Docker Images using Jenkins | Tutorial for Beginners

This tutorial will guide you How to build Docker image using Jenkins also you will learn Jenkins docker integration step by step