在詹金斯中使用脚本运行在不同的阶段

I run the following script which works

 sh """
    mkdir -p /go/src/git.company/mfr/go-proj
    cp -R $WORKSPACE/* /go/src/git.company/mfr/go-proj
    cd  /go/src/git.company/mfr/go-proj
    go test -v ./...
 """

but when I run it like this I got erorr , why ?

 sh   "mkdir -p /go/src/git.company/mfr/go-proj"
 sh   "cp -R $WORKSPACE/* /go/src/git.company/mfr/go-proj"
 sh   "cd  /go/src/git.company/mfr/go-proj"
 sh   "go test -v ./..."

any idea why ?

The file starts with #!/usr/bin/env groovy

Each "sh" is unique invocation. Environment is not shared.

Following will run under two different shells. change of directory will not be reflected to "go test" line

 sh   "cd  /go/src/git.company/mfr/go-proj"
 sh   "go test -v ./..."