Sai Koti
Sai Koti

Reputation: 177

would like to know the difference between sh(hostname) and sh "hostname" in jenkins pipelines

I am using jenkins pipeline and below script in a thought of it would go inside the node and print out the hostname but

node {

    echo "Inside the machine"
    sh (hostname)
}

resulted failure and its saying ..

[Pipeline] sh

[test_sh_in_pipelines] Running shell script

but it worked when i try

node {

    echo "Inside the machine"
    sh ("hostname")
}

please point out what happens when sh() starts interpreting

Upvotes: 1

Views: 702

Answers (1)

Istvan Szekeres
Istvan Szekeres

Reputation: 189

In the first case hostname is treated as a variable, having the value "c41f13de2853". It tries to execute the value as a shell command, which obviously does not exist.

In the second case "hostname" is a literal string which has nothing to do with the variable, so it just executes it as a command. The hostname command, when executed, prints the actual hostname (c41f13de2853).

Upvotes: 3

Related Questions