The method to solve the problem that Jenkins slave node cannot perform File operation through shell

File-related operations cannot be performed on the Jenkins slave, and all operations will be performed on the master.

It can be solved by bash shell. For example, you want to detect whether a folder exists and whether there are files in it.

 

def folder="/test"
def isFolderEmpty=sh(returnStdout: true, script: '''
    if [ -d '''+folder+''' ]; then
        [ "$(ls -A '''+folder+''')" ] && echo "true" || echo "false"
    be''')

    if(isFolderEmpty.startsWith("true")){
        echo "Folder exists and contains files."
    }else{
        echo "Folder does not exists or does not contain any file."
    }

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326572148&siteId=291194637