1

背景,我们刚刚开始使用 conan 并希望将其与 Jenkins 管道构建集成,这对我们来说也是新的。

我有一个简单的管道作业,它遍历 yaml 文件以发现产品中使用的组件,然后调用另一个管道 UploadRecipe,下载组件源,找到配方并将它们上传到工件中的相关存储库

但是,它在工作区/UploadRecipe@tmp 中留下了一大堆 conan.tmp 目录

$ pwd /jenkins_conan/workspace/UploadRecipe@tmp 
$ ls -1
conan.tmp1453946246097996081
conan.tmp2037444640117259875
conan.tmp3926464088111486375
conan.tmp7293377119892400567
conan.tmp868991149159211380

管道没有失败,但它们从未被清理干净,它也发生在我们用来生成消耗 GB 的大型 iso 文件的其他柯南相关管道中,但上传配方示例更易于解释并显示相同的行为。

我的管道 groovy 脚本有问题吗?

即是否有一些我应该调用的命令来整理?

properties([parameters([string(description: 'Name/Version', name: 'name_version', defaultValue: 'base/1.0.2'),
                        string(description: 'User/Channel', name: 'user_channel', defaultValue: 'release/stable'),
                        string(description: 'SVN repository branch', name: 'svn_repo_branch', defaultValue: 'tags/CONAN_REL_1.0.2'),
                        string(description: 'SVN repository url', name: 'svn_repo_url', defaultValue: 'svn+ssh://$USER@svnserver/svncmake/base/'),
                        string(description: 'Artifactory', name: 'artifactory', defaultValue: 'my-artifactory'),
                        string(description: 'Upload repo', name: 'uploadRepo', defaultValue: 'stable-release')
                       ])])

node('buildserver') {
    withEnv(['PATH+LOCAL_BIN=/xxxxx/release/.virtualenvs/jfrog/bin']) {
        currentBuild.displayName = params.name_version + "@" + params.user_channel
        def server
        def client
        def uploadRepo
        def mysvncreds = 'creds-for-svn'
        def SVN_repo_url

        deleteDir()

        stage("Configure/Get recipe"){

            server = Artifactory.server params.artifactory
            client = Artifactory.newConanClient()

            uploadRepo = client.remote.add server: server, repo: params.uploadRepo

            dir("_comp_repo"){
                SVN_repo_url = params.svn_repo_url + params.svn_repo_branch
                checkout([$class: 'SubversionSCM', locations: [[credentialsId: mysvncreds, depthOption: 'files', ignoreExternalsOption: true, local: '.', remote: SVN_repo_url ]]])
            }
        }

        stage("Export recipe"){
            dir("_comp_repo"){
                myrecipes = ['conanfile.py', 'conanfile_policy.py', 'conanfile_rpm.py']

                for(int i = 0; i < myrecipes.size(); i++) 
                { 
                    def thisrecipe = myrecipes[i]
                    if (fileExists(thisrecipe)) {
                        mycommand = "export ./" + thisrecipe + " "  + params.user_channel
                        client.run(command: mycommand )
                    } else {
                        echo thisrecipe
                    }
                }
                client.run(command: "search" )
            }
        }

        stage("Upload recipe to Artifactory"){
            def name_version = params.name_version
            string myname = name_version.split("/")[0]
            string myversion = name_version.split("/")[1]
            String command = "upload ${myname}*/*@${params.user_channel} -r ${uploadRepo} --all --confirm --retry 3 --retry-wait 10"

            client.run(command: command)
        }
    }
}
4

1 回答 1

0

在 bash 中使用 find 和 remove 执行此操作

find /jenkins_conan/workspace/UploadRecipe@tmp -type f -name 'conan.tmp*' -exec rm -v {} \;

或尝试将此添加到您的管道中

node('yournode') {
     ..
    stage 'removing cache files'
    def ws = pwd()
    def file = ws + '/conan.tmp*'
    sh 'rm ' + file + ' -rf' 
}
于 2018-08-24T11:00:01.140 回答