如何在 Jenkins 管道中创建 CIFS 共享配置?

How can I create a CIFS Share configuration in a Jenkins pipeline?

我需要为 cifsPublisher 重新配置自定义主机和凭据,从以下内容开始:

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
            ]]
        )

我需要将其更改为类似于以下内容:

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
            ]]
        )

我的 CloudBees 服务器每天使用不同的凭据向不同的主机发送 30 个部署,并且 activity 这一级别将继续增长。每天都会创建很多cifs配置,导致配置页面和cifs配置变得难以管理。

我使用带有 sh jenkins 插件的 sambclient 工具解决了这个问题,如下所示

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

smbclient 允许您使用 -c 完美嵌入 script.sh 连接并执行选项,这与

相同
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)