Home > Back-end >  How can I create a CIFS Share configuration in a Jenkins pipeline?
How can I create a CIFS Share configuration in a Jenkins pipeline?

Time:10-23

I need to reconfigure a custom host and credentials for a cifsPublisher, beginning with the following:

cifsPublisher(publishers: 
            [[
                configName: 'fooConfig',
                transfers: 
                    [[
                        cleanRemote: true,
                        excludes: '',
                        flatten: false,
                        makeEmptyDirs: false,
                        noDefaultExcludes: false,
                        patternSeparator: '[, ] ',
                        remoteDirectory: "/fooRemote/",
                        remoteDirectorySDF: false,
                        removePrefix: '/build',
                        sourceFiles: "build/**"
                    ]],
                usePromotionTimestamp: false,
                useWorkspaceInPromotion: false,
                verbose: false
            ]]
        )

I need to change it to something similar to the below:

cifsPublisher(publishers: 
            [[
                config: [[
                        hostName: Ipv4,
                        user: domain\username,
                        password: secret,
                        share: baseDirectory
                    ]],
                transfers: 
                    [[
                        cleanRemote: true,
                        excludes: '',
                        flatten: false,
                        makeEmptyDirs: false,
                        noDefaultExcludes: false,
                        patternSeparator: '[, ] ',
                        remoteDirectory: "/public/",
                        remoteDirectorySDF: false,
                        removePrefix: '/share',
                        sourceFiles: "share/**"
                    ]],
                usePromotionTimestamp: false,
                useWorkspaceInPromotion: false,
                verbose: true
            ]]
        )

My CloudBees server is sending 30 deployments per day to different hosts and with different credentials, and this level of activity will continue to grow. Many cifs configs are being created daily, which results in the config page and cifs configurations becoming difficult to manage.

CodePudding user response:

I solved this issue using sambclient tool with sh jenkins plugin as follows

sh: "smbclient \\\\\\\\${host}\\\\${sharedFolder}-U=${domain}\\\\${user}%${secret} -c 'prompt OFF; recurse ON; lcd ${buildpath} ; mput * ;'"

smbclient let you connect with and execute options using -c perfect to embedded in a script.sh, this is the same as

smbclient \\${host}\${sharedFolder}-U=${domain}\${user}%${secret}
>prompt OFF       --This avoid asking for a prompt in any file
>recurse ON       --Recursive mode
>lcd ${buildpath} --Declare my local path to smbclient
>mput *           --mput copy all files that matches with a mask (global pattern)
  • Related