From within a Jenkins pipeline you can any external program. If your pipeline will run on Unix/Linux you need to use the sh command. If your pipeline will run on MS Windows you'll need to use the bat command.

Naturally the commands you pass to these will also need to make sense on the specific operating system.

In this example first we use the internal echo command of Jenkins.

Then we call sh and run the echo of our Unix shell.

Then we execute the hostname command and finally the uptime command.

pipeline {
    agent { label 'master' }
    stages {
        stage('build') {
            steps {
                echo "Hello World!"
                sh "echo Hello from the shell"
                sh "hostname"
                sh "uptime"
            }
        }
    }
}

The result looks like this:

Started by user Gabor Szabo
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/simple-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (build)
[Pipeline] echo
Hello World!
[Pipeline] sh
[simple-pipeline] Running shell script
+ echo Hello from the shell
Hello from the shell
[Pipeline] sh
[simple-pipeline] Running shell script
+ hostname
s17
[Pipeline] sh
[simple-pipeline] Running shell script
+ uptime
 17:15:35 up 3 days,  1:59,  0 users,  load average: 0.00, 0.00, 0.00
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

MS Windows

A few examples in Windows:

Show the name of the computer (a bit like hostname on Unix):

bat 'wmic computersystem get name'

Print out the content of the PATH environment variable as seen by Windows.

bat 'echo %PATH%'

Of course we could have printed the PATH environment variable without invoking an external call:

echo env.PATH

Print out all the environment variables seen by Windows.

echo bat(returnStdout: true, script: 'set')