Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When ever I invoke shell in jenkins pipeline step using sh it gives error Attempted to execute a step that requires a node context

Tags:

I am creating jenkins pipeline where I am defining agent stages and steps. In steps when I am using sh it throws error:

ERROR: Attempted to execute a step that requires a node context while ‘agent none’ was specified. Be sure to specify your own ‘node { ... }’ blocks when using ‘agent none’

Below is throwing the error:

pipeline {
    agent none
    stages {

        stage('Build2') {
            steps {
               sh 'echo "hello world" '
            }  
        }
    }
}

But when I use:

pipeline {
    agent none
    stages {

        stage('Build2') {
            steps {
               echo "hello world"
            }    
        }
    }
}

This works fine

I have used other commands using sh and getting same error.

I am not sure why invoking sh requires a node context.

like image 783
amit sharma Avatar asked Jul 08 '19 15:07

amit sharma


1 Answers

First of all echo step and sh step are very different.

Second of all why would you do agent none and then run something that would assume a particular OS on the executing machine?

One of the solutions would be using agent any.

Another thing, this is what jenkins documentation mentions about agent none:

When applied at the top-level of the pipeline block no global agent will be allocated for the entire Pipeline run and each stage section will need to contain its own agent section. For example: agent none

like image 123
hakamairi Avatar answered Sep 17 '22 07:09

hakamairi