Home > Software engineering >  Jenkins @Libs adds folders after jenkins update
Jenkins @Libs adds folders after jenkins update

Time:09-28

I'm migrating an old Jenkins buildserver i did not set up to a new updated version and that broke the groovy scripts since it's not naming folders in the @libs the same way it did before, maybe it's some setting that is changed.

@lib structure on the old Jenkins 2.204:

D:\jenkins_workspace\<name of workspace>@libs\PC_Lib\PC_Scripts

on the new install with Jenkins 2.361 the @lib looks like this:

D:\jenkins_workspace\<name of workspace>@libs\46cbfc656d3cc901a720a5a9085086f64d931aaa512386cb7be1cd2ca870a4ed\PC_Scripts

The setup: Windows server 2022 Jenkins 2.361.1 SCM = Subversion (SVN) 1.8

In Groovy files they refer to the script like this:

def SCRIPT_PATH = "${env.WORKSPACE}@libs/PC_Lib/PC_Scripts"

Is there any way of using the old way with the direct naming of the library name instead of the UUID name?

CodePudding user response:

I did not find a direct solution for this, instead i use a script{} that returns the folder name or UUID depending on what it finds in the folder. When the folder is found the name is returned and set to a variable that is used instead of a hardcoded folder name.

def pc_lib_folder = script {
    def folders = []
    def dir = new File("${env.WORKSPACE}@libs")
    dir.eachFileRecurse (FileType.DIRECTORIES) { file ->
       folders << file
    }
    return folders
        
    def FOLDER_NAMES = ["<Library name>", "<UUID>"]
    def folder = FOLDER_NAMES[0]
                
    if ( dir.contains(FOLDER_NAMES[0]) ) {
        folder = FOLDER_NAMES[0]
    }
    else if ( dir.contains(FOLDER_NAMES[1]) ) {
        folder = FOLDER_NAMES[1]
    }
    else {
        folder = "No directories found"
    }
    echo "${folder}"
}

This is not a final solution but it works for now atleast.

  • Related