/bin/sh: 0: pipeline@tmp/durable-abcdef/script.sh.copy: No such file or directory

I am adding Jenkins in Android project and the build my one of my branches in MultiProject pipeline job.

but it is giving “/bin/sh: 0: pipeline@tmp/durable-abcdef/script.sh.copy: No such file or directory”

that is my pipline code:

    agent any

    environment {
        JAVA_OPTS = "-Dorg.jenkinsci.plugins.durabletask.BourneShellScript.HEARTBEAT_CHECK_INTERVAL=86400"
    }


    options {
            // prevent multiple builds from running concurrently, that come from the same git branch
            disableConcurrentBuilds()
    }


    stages {
        stage('Build') {
            steps {
                echo 'Building..'
                sh '''
                echo "This is a temporary script" > /workspace/script.sh.copy
                '''
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
                // Add steps to test if needed
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying....'
                // Add deployment steps if needed
            }
        }
    }
}

This is a Jenkins bug, it is happening to me randomly too.
Also you should remove the > /workspace/script.sh.copy and JAVA_OPTS
that will confuse the people here.
It looks like the controller execute the step before the script file gets written to the agent machine.

Meet same issue here too.
Do you know how to solve this bug or how to deal with it? It is happenning to me everytime.

I’ve found out. In my case, my shell block is

sh '''#!/usr/bin/bash ...'''

But in my agent, /usr/bin/bash this path is not existed.
So I fix it to a valid path: /bin/bash, then jenkins won’t raise error again.

Hope it’s helpful.