Perforce Birds of a Feather An introduction to
Perforce Birds of a Feather An introduction to the ‘P 4’ Plugin and update on the latest features. Paul Allen – Perforce Software 2016 #Jenkins. World
Introduction ◦ ◦ ◦ ◦ The Perfect Monorepo P 4 plugin Getting started Perforce Operations Workspace management Polling, triggers and reviews P 4 Groovy
The Perfect Monorepo What is a Monorepo? © 2016 Cloud. Bees, Inc. All Rights Reserved
One Repo to rule them all, One Repo to find them, One Repo to bring them all and in the server bind them. © 2016 Cloud. Bees, Inc. All Rights Reserved
One Store all sources, projects and sub projects; even artifacts, tooling, docs and test reports. . .
One History Boldly go across source and time Reproduce any source at any point in time
Global Access Any file any where Fast Global Distribution Fine grain protections
P 4 Plugin Perforce plugin support for Jenkins © 2016 Cloud. Bees, Inc. All Rights Reserved
Disambiguation ◦ Community ‘Perforce’ plugin https: //wiki. jenkins-ci. org/display/JENKINS/Perforce+Plugin ◦ Perforce Supported ‘P 4’ plugin https: //wiki. jenkins-ci. org/display/JENKINS/P 4+Plugin
The ‘P 4’ plugin ◦ Why Efficient use of Perforce to reduce server load. ◦ P 4 Java Pure Java solution No ‘P 4’ executable to install and keep up-to-date. ◦ Latest features Streams, sync and clean up options
Getting started First the basics… © 2016 Cloud. Bees, Inc. All Rights Reserved
Getting started ◦ Configure a basic connection ◦ Managing Workspaces ◦ Source code management from the perspective of a Freestyle Job and Pipeline DSL
Credentials ◦ Perforce Credentials Shared Credentials Managed from one location Independent from the Job configuration Update connection details in one location ◦ Credential Types Perforce Password Credential Perforce Ticket Credential
Credentials ◦ Connection information Username/Password Perforce address and port workshop. perforce. com: 1666 ◦ Password credentials Username Password ID (useful to reference in the DSL) Description
Credentials ◦ Ticket based security Perforce generated Ticket String $ p 4 login –p 4 E 034 A 8812 F 81 B 38229 BF 8 FA 62 B 0 FEB 1 Location of Perforce P 4 TICKET file /home/pallen/. p 4 ticket ◦ SSL and Trust Check the SSL box to add the ssl: part to P 4 PORT Use p 4 trust or click test to get the fingerprint
Perforce Operations SCM Checkout, Build Steps and Post Build © 2016 Cloud. Bees, Inc. All Rights Reserved
SCM Operations ◦ Populate p 4 sync / checkout Synchronize the files in the Workspace prior to build. ◦ Unshelve p 4 unshelve Unshelve code into the Workspace prior to build. ◦ Label p 4 tag Automatic label against the populated files in the Workspace, post build. ◦ Publish p 4 publish Submit files back into Perforce, post build.
Populate ◦ Auto Cleanup and Sync populate: [$class: 'Auto. Clean. Impl', delete: true, have: true, modtime: false, quiet: false, pin: '' ] ◦ Force Clean and Sync populate: [$class: 'Force. Clean. Impl', have: false, pin: '', quiet: true ]
Unshelve ◦ Unshelve Build Step Unshelve the change as a Build step defined in the Job Files are unshelved and resolved prior build. p 4 unshelve resolve: 'at', shelf: '12345'
Label ◦ Automatic label Label on success option Uses Populate Client’s View ◦ Name & Description p 4 tag raw. Label. Name: '${JOB_NAME}-passed', raw. Label. Desc: '''Jenkins job: ${JOB_NAME} Jenkins build: ${BUILD_TAG} Jenkins build date: ${BUILD_ID} Jenkins build number: ${BUILD_NUMBER}'''
Publish ◦ ◦ Connection & Workspace Use a narrow view Virtual stream Read/Write access for files Set Workspace option ALLWRITE or use filetype +w
Publish p 4 publish credential: 'phooey 1666', publish: [ $class: 'Submit. Impl', delete: false, description: 'Build: ${BUILD_TAG}', only. On. Success: false, reopen: false], workspace: [ $class: 'Stream. Workspace. Impl', charset: 'none', format: 'jenkins-${JOB_NAME}-publish', pin. Host: false, stream. Name: '//streams/st 1 -main']
Workspace Management Jenkins and Perforce Workspaces © 2016 Cloud. Bees, Inc. All Rights Reserved
Workspaces ◦ Jenkins workspace Location of files (on the master or slave) for Jenkins to build ◦ Perforce workspace Location where Perforce will manage the versioned an non-versioned files ◦ Shared root Recommend Perforce and Jenkins workspaces share the same root One Jenkins workspace to map to one Perforce workspace
Workspaces ◦ Workspace Configuration Streams Workspace Manual Workspace Template Workspace Static Workspace (predefined) Spec Workspace (spec depot or file) workspace: [$class: 'Stream. Workspace. Impl', charset: 'none', format: 'jenkins-${NODE_NAME}-${JOB_NAME}', pin. Host: false, stream. Name: '//streams/st 1 -main']
Workspace View Mapping +---Ace. Project | +---src | +---test | +---docs | +---libs +---Blast. Project | +---src | +---test | +---docs | +---libs | | +---blast. jar //depot/Ace. Project/. . . -//depot/Ace. Project/docs/. . . -//depot/Ace. Project/libs/. . . //depot/Blast. Project/libs/. . .
Workspace //depot/Ace. Project/. . . //{client}/Ace/. . . -//depot/Ace. Project/docs/. . . -//depot/Ace. Project/libs/. . . -//{client}/Ace/docs/. . . -//(client}/Ace/libs/. . . //depot/Blast. Project/libs/. . . //{client}/Ace/plugins/. . .
Workspace Perforce workspace +---Ace. Project | +---src | +---test | +---docs | +---libs +---Blast. Project | +---src | +---test | +---docs | +---libs | | +---blast. jar Jenkins Workspace +---Ace | +---src | +---test | | | +---plugins | | | | +---blast. jar
Variable expansion ◦ Built in Variables /env-vars. html ◦ Perforce Variables P 4_CHANGELIST P 4_PORT P 4_TICKET P 4_CLIENT P 4_USER ◦ Workspace Name View jenkins-${NODE_NAME}-${JOB_NAME} //depot/… //jenkins-${NODE_NAME}-${JOB_NAME}/…
Polling, Triggers and Reviews Still polling? © 2016 Cloud. Bees, Inc. All Rights Reserved
Polling… if you must ◦ Pin at Label/Change Pin build at Perforce Label ◦ Polling build Filters Exclude changes from Depot path Exclude changes from user Exclude changes outside view mask Poll on Master using Latest Build Polling per Change ◦ Populate modes Preview check Only (sync –k)
Triggers ◦ Perforce triggered build ◦ P 4 Trigger curl --header 'Content-Type: application/json' --request POST --data "payload={change: 200, p 4 port: "perforce. com: 1666"}" http: //jenkins: 8080/p 4/change ◦ P 4 Review Build triggered by Perforce Swarm. Review or Change unshelved into workspace prior to build
Swarm [POST] https: //swarm: deadbeef@perforce. com: 8443 /job/my. Job/review/build ? change={change}&status={status}&review={review} &pass={pass}&fail={fail}
P 4 Groovy P 4 command access for Groovy © 2016 Cloud. Bees, Inc. All Rights Reserved
P 4 Groovy ◦ P 4 Grovy object Credential Workspace ws = [$class: 'Stream. Workspace. Impl', charset: 'none', format: 'jenkins-${JOB_NAME}', pin. Host: false, stream. Name: '//streams/proj. Ace'] p 4 = p 4(credential: 'phooey', workspace: ws)
P 4 Groovy Methods ◦ Run Requires: command, arguments (‘, ’ separated String) Returns: tagged output (specifically Map<String, Object>[]) p 4. run(’changes', '-m 5, //. . . ') ◦ Getters p 4. get. User. Name() p 4. get. Client. Name()
P 4 Groovy Methods ◦ Fetch Requires: spec type, spec id Returns: a spec as a Map client = p 4. fetch(‘client’, ‘my_ws’) ◦ Save Requires: the spec as a Map Returns: tagged output (specifically Map<String, Object>[]) p 4. save(client)
P 4 Groovy ◦ SCM Steps Populate Unshelve Label Publish p 4 sync / checkout p 4 unshelve p 4 tag p 4 publish ◦ P 4 Groovy Populate Unshelve Label Publish p 4. run('sync', '-q, //. . . ') p 4. run(’unshelve', '-s 123456'). . .
P 4 Groovy ◦ Example or Demo
Questions
© 2016 Cloud. Bees, Inc. All Rights Reserved 201 6 #Jenkins. World
- Slides: 41