If you use the syntax generator to create a checkout step that includes a polling build filter the following text is created:
filter: [userFilter('BUILDER'), viewFilter('''//corvus/main/workers''')],
If you try to execute this code in Pipeline (jenkinsfile or defined in job window) it will fail with error:
[Pipeline] End of Pipeline java.lang.IllegalArgumentException: Arguments to class org.jenkinsci.plugins.p4.filters.FilterPatternListImpl have to be explicitly named at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:254) at org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable.instantiate(UninstantiatedDescribable.java:167) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:372) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerceList(DescribableModel.java:463) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:365) at org.jenkinsci.plugins.structs.describable.DescribableModel.buildArguments(DescribableModel.java:318) at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:259) Caused: java.lang.IllegalArgumentException: Could not instantiate {credential=MasterServer, filter=[@userFilter(<anonymous>=BUILDER), @viewFilter(<anonymous>=//corvus/main/workers ...cut... filter: Filter{FilterPathImpl(path: String) | FilterPatternListImpl(patternText: String, caseSensitive: boolean) | FilterPerChangeImpl(perChange: boolean) | FilterUserImpl(user: String) | FilterViewMaskImpl(viewMask: String)}[] ...cut...
To fix the problem you need to name the variables. For example:
filter: [ userFilter(user: 'BUILDER'),viewFilter(viewMask: '''//corvus/main/workers''')],
Note: Checked this by looking at the code https://github.com/jenkinsci/p4-plugin/blob/d673f91a923c3d80e5570dd4a41930b57f62befc/src/main/java/org/jenkinsci/plugins/p4/filters/FilterViewMaskImpl.java
If you run the build manually it works OK and if you just have the 'userFilter' on its own works OK. But if you try to use 'viewFilter' on its own or with 'userFilter' you get an exception when polling. For example:
Started on Mar 8, 2018 4:27:00 PM P4: Polling on: master with:jenkins-master-FilteredPipeline-0 Found last change 347 on syncID jenkins-NODE_NAME-FilteredPipeline-EXECUTOR_NUMBER ... p4 client -o jenkins-master-FilteredPipelineSamuel-0 + ... p4 info + P4 Task: establishing connection. ... server: 10.1.3.217:1666 ... node: vm-karl-swarm174-xenial P4: Polling with range: 347,now ... p4 changes -m20 //jenkins-master-FilteredPipeline-0/...@347,now + ... p4 change -o 348 + ... p4 describe -s 348 + P4 Task: attempt: 1 P4 Task: failed: java.lang.NullPointerException ERROR: polling failed in /var/lib/jenkins/workspace/FilteredPipeline on : P4 Task: failed: java.lang.NullPointerException Done. Took 4 sec No changes
Example full code below:
pipeline { agent any stages { stage('Sync code') { steps { echo "Starting" //checkout perforce(credential: 'MasterServer', filter: [ userFilter(user: 'BUILDER') ], populate: autoClean(delete: true, modtime: false, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: false, replace: true, tidy: false), workspace: manualSpec(charset: 'none', name: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}', pinHost: false, spec: clientSpec(allwrite: false, backup: false, clobber: true, compress: false, line: 'LOCAL', locked: false, modtime: false, rmdir: false, serverID: '', streamName: '//corvus/main', type: 'WRITABLE', view: ''))) //checkout perforce(credential: 'MasterServer', filter: [userFilter(user:'BUILDER'), viewFilter(viewMask:'//corvus/main/workers')], populate: autoClean(delete: true, modtime: false, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: false, replace: true, tidy: false), workspace: streamSpec(charset: 'none', format: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}', pinHost: false, streamName: '//corvus/main')) checkout perforce(credential: 'MasterServer', filter: [viewFilter(viewMask:'//corvus/main/workers')], populate: autoClean(delete: true, modtime: false, parallel: [enable: false, minbytes: '1024', minfiles: '1', threads: '4'], pin: '', quiet: false, replace: true, tidy: false), workspace: streamSpec(charset: 'none', format: 'jenkins-${NODE_NAME}-${JOB_NAME}-${EXECUTOR_NUMBER}', pinHost: false, streamName: '//corvus/main')) } } } }