简体   繁体   English

如何在Perforce和Jenkins中将流与自定义视图映射一起使用

[英]How to use streams with custom view mapping in with Perforce and Jenkins

I'm using Perforce running in a Jenkins Pipeline. 我正在Jenkins管道中运行Perforce。 I checkout from Perforce with this: 我从Perforce结帐:

          checkout scm: [
                $class: 'PerforceScm', 
                credential: 'me', 
                populate: [
                    $class: 'AutoCleanImpl', 
                    delete: true, 
                    modtime: false, 
                    pin: '', 
                    quiet: true, 
                    replace: true
                ], 
                workspace: [
                    $class: 'ManualWorkspaceImpl', 
                    charset: 'utf8', 
                    name: 'jenkins-${NODE_NAME}-${JOB_NAME}', 
                    pinHost: false, 
                    spec: [
                      allwrite: true, 
                      clobber: false, 
                      compress: false, 
                      line: 'LOCAL', 
                      locked: false, 
                      modtime: false, 
                      rmdir: false, 
                      streamName: '',
                      view: '''//depot/main/... //jenkins-${NODE_NAME}-${JOB_NAME}/assets/...
                               -//depot/main/pre_ar_archive/... //jenkins-${NODE_NAME}-${JOB_NAME}/assets/pre_ar_archive/...
                               -//depot/main/tools/... //jenkins-${NODE_NAME}-${JOB_NAME}/assets/tools/...'''
                    ]
                ]
            ]

I use a custom mapping to locate the files I need at a specific folder and exclude folders I do not need. 我使用自定义映射在特定的文件夹中找到所需的文件,并排除不需要的文件夹。

Once checked out, my build stage will run a python script to process the assets. 签出后,我的构建阶段将运行python脚本来处理资产。 This script uses p4python. 该脚本使用p4python。 Once done, it will submit. 完成后,它将提交。 However, when I submit, I get this error: 但是,当我提交时,出现此错误:

"No files to submit.\\n Submit failed -- fix problems above then use 'p4 submit -c 1234'" “没有文件可以提交。\\ n提交失败-修复上述问题,然后使用'p4 Submit -c 1234'”

The problem is this: 问题是这样的:

Perforce error - cannot submit from non-stream client Perforce错误-无法从非流客户端提交

If I run p4 client , I can see that I don't have a Stream defined. 如果运行p4 client ,我可以看到我没有定义Stream。 If I modify my checkout to define a 'streamName', then I find that it will use a default view which is essentially 如果我修改签出以定义“ streamName”,那么我发现它将使用默认视图,该视图实际上是

//depot/main/... //jenkins-${NODE_NAME}-${JOB_NAME}/...

Thus I lose my mapping. 因此,我丢失了映射。

Is there any work around for this? 有什么解决办法吗?

One thing I could do is just use p4v to create the client I need, but then that seems to force me to just invoke all of my perforce commands that the plugin is otherwise doing. 我可以做的一件事就是仅使用p4v创建所需的客户端,但这似乎迫使我仅调用插件执行的所有perforce命令。

I have tried to use p4 client to map it, but when I do, it also changes the view. 我尝试使用p4客户端对其进行映射,但是当我这样做时,它也会更改视图。 p4 documentation indicates that it will do this (use a default view). p4文档指示它将执行此操作(使用默认视图)。

I'm going to assume that //depot/main is a stream (although there are a lot of things about this question that make no sense if it's a stream, like why you ever tried to create a manual client view in the first place if your main depot is a stream depot). 我将假设//depot/main是一个流(尽管关于此问题的很多事情如果是流,则毫无意义,例如为什么您一开始尝试创建手动客户端视图(如果您的主要仓库是流仓库)。 If it's not, there's some entirely other problem going on here, which is something along the lines of your Jenkins client having files checked out that are in some unrelated stream and outside your client view (which would point at some misconfiguration on the Jenkins side, or a really bad bug in your script, or a bad trigger on the server, or something). 如果不是这样,那么这里还会出现其他问题,这与您的Jenkins客户端的问题相似,即文件签​​出的内容不在某些无关的流中,并且不在您的客户端视图之内(这可能意味着Jenkins方面的某些配置错误,或脚本中的错误非常严重,或服务器上的触发错误,等等)。


With streams you construct a view in the form of a stream spec that can then be shared across multiple clients. 使用流,您可以以流规范的形式构造视图,然后可以在多个客户端之间共享该视图。 So your view: 所以你的看法:

//depot/main/... //client/assets/...
-//depot/main/pre_ar_archive/... //client/assets/pre_ar_archive/...
-//depot/main/tools/... //client/assets/tools/...

should be represented as a stream that looks something like this: 应该表示为看起来像这样的流:

Stream: //depot/main-jenkins
Parent: //depot/main
Type: virtual
Paths:
    share ...
    exclude pre_ar_archive/...
    exclude tools/...
Remapped:
    ... assets/...

Then you'd configure your Jenkins client like this (I think; I don't really know anything about the Jenkins configuration): 然后,您可以像这样配置您的Jenkins客户端(我想;我对Jenkins配置一无所知):

            workspace: [
                $class: 'StreamWorkspaceImpl', 
                charset: 'utf8', 
                name: 'jenkins-${NODE_NAME}-${JOB_NAME}', 
                pinHost: false, 
                spec: [
                  allwrite: true, 
                  clobber: false, 
                  compress: false, 
                  line: 'LOCAL', 
                  locked: false, 
                  modtime: false, 
                  rmdir: false, 
                  streamName: '//depot/main-jenkins'
                ]
            ]

Specifying the //depot/main-jenkins stream gives you the automatically generated view for that stream. 指定//depot/main-jenkins流会为您提供该流的自动生成的视图。

Okay adding on to this. 好的,补充一下。 This does work. 这确实有效。 The workspace class needs to be StreamWorkspaceImpl 工作空间类必须为StreamWorkspaceImpl

           checkout scm: [
                $class: 'PerforceScm', 
                credential: 'me', 
                populate: [
                    $class: 'AutoCleanImpl', 
                    delete: true, 
                    modtime: false, 
                    pin: '', 
                    quiet: true, 
                    replace: true
                ], 
                workspace: [
                    $class: 'StreamWorkspaceImpl', 
                    charset: 'utf8', 
                    format: 'jenkins-${NODE_NAME}-${JOB_NAME}', 
                    pinHost: false, 
                    streamName: '//depot/main-jenkins-test'
                ]
            ]

The stream spec that Sam Stafford listed above works. 上面列出的Sam Stafford的流规范有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM