7

I'm trying to sync to Perforce in my pipeline script, but from the documentation I don't see a way to set the "workspace behavior", even though the plugin itself seems to have that capability.

I want the "workspace" to be equivalent to the setting "Manual (custom view)" I can configure in the UI as described here. What parameters do I need to pass to the p4sync task to achieve that?

Tilo
  • 3,255
  • 26
  • 31

1 Answers1

10

You will need to use the full checkout DSL, the p4sync DSL is only basic. The easiest way is to use the snippet generator (Pipeline Syntax link), select checkout: General SCM then Perforce Software from the SCM list.

You will then be able to define a detailed View. For example:

checkout([
  $class: 'PerforceScm', 
  credential: 'phooey1666', 
  populate: [
    $class: 'AutoCleanImpl', 
    delete: true, 
    modtime: false, 
    pin: '', 
    quiet: true, 
    replace: true
  ], 
  workspace: [
    $class: 'ManualWorkspaceImpl', 
    charset: 'none', 
    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/... //jenkins-${NODE_NAME}-${JOB_NAME}/...
        -//depot/tests/... //jenkins-${NODE_NAME}-${JOB_NAME}/tests/...'''
    ]
  ]
])
paul allen
  • 238
  • 2
  • 8
  • 1
    Presumably this syncs the entire view. Is there a way to separate specifying the mapping from the set of files to be checked out? For example - we have a many large depots, and each project knows what it needs. So if we could specify a simple high level mapping we can let the build do the syncing. Otherwise we either map+sync far too much, or map+sync based on the project - duplicating information and increasing maintainance. (comment 5 min rule) – simon.watts Nov 07 '17 at 11:57
  • With a ManualWorkspace the View (map+sync) is your only, you could add multiple `checkout` step in your pipeline or delegate some to a Groovy library. Just remember that you must use different workspace names for multiple `checkout` steps. – paul allen Nov 09 '17 at 19:12
  • Streams may work better in a 'project' environment as each child will inherit the view from it's parent, saving the duplication of complex mappings. The Jenkins `p4-plugin` supports streams in ManualWorkspaceImpl and in StreamsWorkspaceImpl depending on how much control you need. – paul allen Nov 09 '17 at 19:16
  • Streams seem like a good options - although I'll have to persuade the large legacy projects that I'm trying the Jenkify to adopt them. – simon.watts Nov 10 '17 at 15:34
  • This view definition would not work because of leading spaces, but adding `stripIndent()` to the view string may be all that is needed. – haridsv Jul 31 '18 at 13:01