package org.jenkinsci.plugins.p4.tasks; import hudson.AbortException; import hudson.FilePath.FileCallable; import hudson.remoting.VirtualChannel; import java.io.File; import java.io.IOException; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; import jenkins.security.Roles; import org.jenkinsci.plugins.p4.changes.P4ChangeEntry; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.populate.Populate; import org.jenkinsci.plugins.p4.review.ReviewProp; import org.jenkinsci.plugins.p4.workspace.Expand; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.jenkinsci.remoting.RoleChecker; import org.jenkinsci.remoting.RoleSensitive; import com.perforce.p4java.impl.generic.core.Label; public class CheckoutTask extends AbstractTask implements FileCallable<Boolean>, Serializable { private static final long serialVersionUID = 1L; private static Logger logger = Logger.getLogger(CheckoutTask.class .getName()); private final Populate populate; private CheckoutStatus status; private int head; private Object buildChange; private int review; /** * Constructor * * @param populate */ public CheckoutTask(Populate populate) { this.populate = populate; } public void initialise() throws AbortException { ClientHelper p4 = getConnection(); try { // fetch and calculate change to sync to or review to unshelve. status = getStatus(getWorkspace()); head = p4.getClientHead(); review = getReview(getWorkspace()); buildChange = getBuildChange(getWorkspace()); // try to get change-number if automatic label if (buildChange instanceof String) { String label = (String) buildChange; if (p4.isLabel(label)) { Label labelSpec = p4.getLabel(label); String revSpec = labelSpec.getRevisionSpec(); if (revSpec != null && !revSpec.isEmpty() && revSpec.startsWith("@")) { try { int change = Integer.parseInt(revSpec.substring(1)); buildChange = change; } catch (NumberFormatException e) { // leave buildChange as is } } } } } catch (Exception e) { String err = "P4: Unable to initialise CheckoutTask: " + e; logger.severe(err); p4.log(err); throw new AbortException(err); } finally { p4.disconnect(); } } /** * Invoke sync on build node (master or remote node). * * @return true if updated, false if no change. */ public Boolean invoke(File workspace, VirtualChannel channel) throws IOException { return (Boolean) tryTask(); } @Override public Object task(ClientHelper p4) throws Exception { // Tidy the workspace before sync/build p4.tidyWorkspace(populate); // Sync workspace to label, head or specified change p4.syncFiles(buildChange, populate); // Unshelve review if specified if (status == CheckoutStatus.SHELVED) { p4.unshelveFiles(review); } return true; } /** * Get the build status for the parameter map. * * @param map * @return */ private CheckoutStatus getStatus(Workspace workspace) { CheckoutStatus status = CheckoutStatus.HEAD; String value = workspace.getExpand().get(ReviewProp.STATUS.toString()); if (value != null && !value.isEmpty()) { status = CheckoutStatus.parse(value); } return status; } /** * Get the sync point from the parameter map. Returns the head if no change * found in the map. * * @param map * @return */ private Object getBuildChange(Workspace workspace) { // Use head as the default Object build = this.head; // Get Environment parameters from expand Expand expand = workspace.getExpand(); // if a pinned change/label is specified the update String populateLabel = populate.getPin(); if (populateLabel != null && !populateLabel.isEmpty()) { // Expand label with environment vars if one was defined populateLabel = expand.format(populateLabel, false); try { // if build is a change-number passed as a label build = Integer.parseInt(populateLabel); } catch (NumberFormatException e) { build = populateLabel; } } // if change is specified then update String change = expand.get(ReviewProp.CHANGE.toString()); if (change != null && !change.isEmpty()) { try { build = Integer.parseInt(change); } catch (NumberFormatException e) { } } // if label is specified then update String label = expand.get(ReviewProp.LABEL.toString()); if (label != null && !label.isEmpty()) { try { // if build is a change-number passed as a label build = Integer.parseInt(label); } catch (NumberFormatException e) { build = label; } } return build; } /** * Get the unshelve point from the parameter map. * * @param map * @return */ private int getReview(Workspace workspace) { int review = 0; Expand expand = workspace.getExpand(); String value = expand.get(ReviewProp.REVIEW.toString()); if (value != null && !value.isEmpty()) { try { review = Integer.parseInt(value); } catch (NumberFormatException e) { } } return review; } public List<Integer> getChanges(Object last) { List<Integer> changes = new ArrayList<Integer>(); // Add changes to this build. ClientHelper p4 = new ClientHelper(getCredential(), getListener(), getClient()); try { changes = p4.listChanges(last, buildChange); } catch (Exception e) { String err = "Unable to get changes: " + e; logger.severe(err); p4.log(err); e.printStackTrace(); } finally { p4.disconnect(); } // Include shelf if a review if (status == CheckoutStatus.SHELVED) { changes.add(review); } return changes; } public List<P4ChangeEntry> getChangesFull(Object last) { List<P4ChangeEntry> changesFull = new ArrayList<P4ChangeEntry>(); List<Integer> changes = new ArrayList<Integer>(); // Add changes to this build. ClientHelper p4 = new ClientHelper(getCredential(), getListener(), getClient()); try { if (status == CheckoutStatus.SHELVED) { P4ChangeEntry cl = new P4ChangeEntry(); cl.setChange(p4, review); changesFull.add(cl); } // add all changes to list changes = p4.listChanges(last, buildChange); for (Integer change : changes) { P4ChangeEntry cl = new P4ChangeEntry(); cl.setChange(p4, change); changesFull.add(cl); } } catch (Exception e) { String err = "Unable to get changes: " + e; logger.severe(err); p4.log(err); e.printStackTrace(); } finally { p4.disconnect(); } return changesFull; } public CheckoutStatus getStatus() { return status; } // Returns the number of the build change not the review change public Object getSyncChange() { return buildChange; } public Object getBuildChange() { if (status == CheckoutStatus.SHELVED) { return review; } return buildChange; } public void setBuildChange(Object parentChange) { buildChange = parentChange; } public int getReview() { return review; } public void checkRoles(RoleChecker checker) throws SecurityException { checker.check((RoleSensitive) this, Roles.SLAVE); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#37 | 28022 | Paul Allen |
Merge pull request #134 from stuartrowe/JENKINS-66648 [JENKINS-66648] Replace 'now' label with the P4ChangeRef for the current head |
||
#36 | 27175 | Paul Allen |
Prevent dormant multi branch project continiously building. JENKINS-63494 and JENKINS-64193 When scanning a multi branch project if the history of changes is outside of the `Head change query limit` then no changes are found. The old behaviour used the latest change and triggered a build; continuously triggering dormant projects with each new submit. The new behaviour uses the last build change if no changes are found (preventing a triggered build) or if there was no previous builds (in the case of new projects) then the latest changes is used to triggering a build. |
||
#35 | 26579 | Paul Allen |
Prevent logging if Populate quiet flag is set. Originally the Populate quiet flag was passed as a '-q' flag to the command, but some commands using callback streaming handlers still reported output. JENKINS-59750 |
||
#34 | 25909 | Paul Allen |
Merge pull request #103 from williambrode/JENKINS-58686 Don't query submitted changes when syncing to CL 0. JENKINS-58686 |
||
#33 | 25826 | Paul Allen |
Global option to limit change query. By default 'Head change query limit' is set to 0 (no limit) and the plugin will query all changes when looking within a workspace view. For large servers set the value to a range based on commit rate and job queue duration. e.g. 200 global commits/hour and jobs are queued for no longer than 10 hours, so 2000 change query limit (200*10). JENKINS-58116 JENKINS-57870 |
||
#32 | 25651 | Paul Allen |
Merge pull request #100 from stuartrowe/JENKINS-57534 Limit buildChange to the next highest change number within the client's view |
||
#31 | 25437 | Paul Allen |
Skip build if polling finds no/null change. JENKINS-55075 |
||
#30 | 24529 | Paul Allen |
Swarm Commit Event support, refactoring and test. JENKINS-52605 (Fix doc in 'Includes' help bubble for MultiBranch) JENKINS-52066 (Improve Swarm Commit and Branch Event support) |
||
#29 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#28 | 22817 | Paul Allen |
Raise warning if a static label is used during checkout. JENKINS-44852 |
||
#27 | 22315 | Paul Allen |
Pending change cleanup for unshelve. Unshelve would leave files open for add/edit/delete, the 'tidy' option will 'revert -k' the files leaving the content in the workspace, but removing the 'have' list data. Unshelve can now specify a Credential and Workspace, important for situations where more than one sync occurs in a pipeline script. JENKINS-43430 |
||
#26 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#25 | 20873 | Paul Allen | Support Pin to a change in a counter. | ||
#24 | 20787 | Paul Allen |
Polling Fix for use with quiet period. Switched all uses of change/label to P4Revision object and implemented Comparable. The changes to build are now calculated at build time (after the quiet period) not during the polling phase. JENKINS-36883 #review-20780 |
||
#23 | 20620 | Paul Allen |
Change 'now' to the latest change at the point of sync. JENKINS-36883 |
||
#22 | 20179 | Paul Allen | Javadoc fixes for java 8 builds. | ||
#21 | 20012 | Paul Allen | Logging for changelist calculation at checkout. | ||
#20 | 19831 | Paul Allen | (minor format change) | ||
#19 | 19830 | mjoubert | @pallen Add checks for sync CL and head CL | ||
#18 | 19593 | Paul Allen | More minor fixes to satisfy FindBugs Analysis. | ||
#17 | 19581 | Paul Allen | Minor fixes to satisfy FindBugs Analysis. | ||
#16 | 16815 | Paul Allen |
Enable early binding for CHARSET Expose CHARSET to AbstractTask to allow the charset to be set at the point the client workspace is set as current in ClientHelper. |
||
#15 | 16515 | Paul Allen |
Extend support for 'now' revision specifier. If 'now' is used it will be substituted for the latest change within the scope of the workspace view. |
||
#14 | 16390 | Paul Allen |
Update change/file reporting. Use `p4 changes @=1234` to get change summary and `p4 files -m50 @=1234` to get limited file list. |
||
#13 | 15750 | Paul Allen |
Use a P4Revision object and not int/String as Object. In sure that there is no ambiguity with the revision specifier. Should fix change summary when using the Workflow plugin. JENKINS-30425 |
||
#12 | 15490 | Paul Allen | JENKINS-29943: Check for empty param values | ||
#11 | 15394 | Paul Allen |
Workflow-DSL functionality. Tested workflow DSL against 1.596.1 older functionality tested against 1.580.1 @sven_erik_knop |
||
#10 | 15293 | Paul Allen |
Add retry attempts to Perforce Tasks. If a task fails due to an exception then the task will retry based on the value specified in the connection Credential. |
||
#9 | 13681 | Paul Allen |
Abstracted Expand class from Workspace. Added support for Label variable expansion in the name and description. |
||
#8 | 12953 | Paul Allen |
Update logging to support expand/collapse divs. - Additional Publish logging |
||
#7 | 12932 | Paul Allen |
New Populate CheckOnly Implementation. No tidy or sync steps only a have list update. Intended for use with polling and triggering other Jenkins jobs. #review-12933 @mjoubert |
||
#6 | 12417 | Paul Allen |
Extend Jenkins support back to 1.568 - remove @Override annotations - remove jenkins.security.Roles |
||
#5 | 12178 | Paul Allen | minor whitespace fix. | ||
#4 | 12177 | Paul Allen |
@palmr - Enable the 'Pinning' option with a 'Build Now' task. https://github.com/jenkinsci/p4-plugin/pull/9 |
||
#3 | 11626 | Paul Allen |
Workflow support. - Updated the plugin to the latest LTS Jenkins release 1.580.3. - Updated P4Java to 2014.1 Tested with simple ‘static’ workspace, there may be limitations with ‘manual’ workspace. Plan to add DSL support by extending the SCMStep class. #review-11537 JENKINS-24206 |
||
#2 | 11475 | Paul Allen |
Build children at parent's change. The change calculated by the parent is passed to the children. This avoids change drift for long builds with delayed executors. |
||
#1 | 11334 | Paul Allen |
Remote slave support for Publish Perforce Publish commands need to be executed from the remote slave. - Includes refactoring into task package |
||
//guest/perforce_software/p4jenkins/main/src/main/java/org/jenkinsci/plugins/p4/CheckoutTask.java | |||||
#16 | 11108 | Paul Allen |
Changelist report ordering. Review files needs to be at the top of the change pages so developers can easily see what their changes are. |
||
#15 | 11084 | Paul Allen |
(mjoubert) Fully populate changelog.xml Replaces sparse change log which only recorded the change number. The change is now recorded in full allowing faster page load times. The number of files listed in the change is limited to 50; to view larger changes please add a repo browser such as Swarm, Fisheye, P4Web, etc… |
||
#14 | 10939 | Paul Allen |
Tidy up changes. - Moved duration timings to ClientHelper and measure each task individually. - White space/formatting on P4ChangeEntry. - Temporarily backed-out p4-plugin.properties file (could damage builds - need to understand requirements) |
||
#13 | 10937 | Paul Allen |
(mjoubert) pull request P4_CHANGELIST variable Adding a local properties file solves the problem better. I can set my build name for example to #${BUILD_NUMBER}.${PROPFILE,file="p4-plugin.properties",property="buildChange"} or use the env-inject plugin to use it later. We could add other items i suppose |
||
#12 | 10801 | Paul Allen |
Improvements to SCM Polling Moved change list calculation into a new class CheckoutChanges. Should enable normal build to build every thing and poll to follow polling behaviour: limit based on pin and per-change if set. JENKINS-25300 |
||
#11 | 10775 | Paul Allen |
Fix change detection when using a moving label If a build was pinned or built from a label, the label name was recorded <buildChange>. If the label is updated between builds then comparing against an earlier build will give you the wrong result. This fix stores the automatic label ‘Revision’ field and stores this in <buildChange>. NOTE: you will need to run a manual build to flush the label, so that the last build has a change number. JENKINS-25300 |
||
#10 | 10755 | Paul Allen |
Separate name space for 'label' parameter. Perforce Review endpoint added `label`, `change`, `status`, `pass`, and `fail` parameter into the environment, which is a shared name space. This clashed with the default `label` matrix name and causing users issues. The change prefixes the review parameters with `p4.` on addition to the environment. |
||
#9 | 10466 | Paul Allen |
Fix first build when pinned at change-number. On first build the logic would treat a pinned changelist build as a label, causing a processing error later for change reporting. |
||
#8 | 9987 | Paul Allen | Better logging for slave connections. | ||
#7 | 9980 | Paul Allen |
Changed error reporting to use AbortException. - Use direct access of scm attributes, not via build.getProject().getScm() - Improved logging around labels/changes. |
||
#6 | 9851 | Paul Allen | Merging using p4-jenkins | ||
#5 | 9803 | Paul Allen | Merging using p4-jenkins | ||
#4 | 9787 | Paul Allen | Merging using p4-jenkins | ||
#3 | 9769 | Paul Allen | Copying using p4-jenkins | ||
#2 | 9738 | Paul Allen | Merging using p4-jenkins | ||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4/CheckoutTask.java | |||||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4_client/CheckoutTask.java | |||||
#14 | 9371 | Paul Allen | Fix issue when label could be empty (called by Swarm or Review URL). | ||
#13 | 9115 | Paul Allen |
Initial implementation of workspace Cleanup and Sync options. - Includes 3 modes: Automatic Clean/Sync, Force Clean/Sync, Sync Only Automatic Clean/Sync Uses reconcile to clean up workspace and sync changes. Force Clean/Sync Force sync of all files (does not remove files yet...) Sync Only Normal sync with no cleanup TODO: - remove of files in Force Clean/Sync mode - Inline help - Update docs - Add unit/functional tests |
||
#12 | 9069 | Paul Allen |
Adding initial support for tagging Jenkins builds as Perforce Automatic Labels. Only implements TagAction (manual labels); TagNotifier and test cases TODO. |
||
#11 | 9055 | Paul Allen |
Label support. Build at a label using the pram 'label'. This includes adding the label to the ChangeEntry, building the change reports and Browser links to Swarm. (TPI-102) |
||
#10 | 8969 | Paul Allen |
Adds all contributing change-lists for the build to the change log (using p4 cstat). - Includes exception logging for server connection to the Jenkins console. |
||
#9 | 8940 | Paul Allen |
Major refactor for the ConnectionHelper class to simplify serialisation. Fixed remote Jenkins JNLP slave connection issue. ClientHelper now extends ConnectionHelper and takes on all methods that require a client workspace. P4StandardCredentials is sent to the remote node instead of Credentials ID due to an issue accessing the Credentials store over a remote connection. For simplicity Client ID (workspace name) is serialised instead of the Workspace object. |
||
#8 | 8926 | Paul Allen |
Bug fix when unshelving files with the Template workspace option. p4-java was unable to switch the worksapce view (without the -f flag) if there were files open. - Improved logging (as this error was hidden) - Added test case for this condition. |
||
#7 | 8924 | Paul Allen | Sync workspace to last change in workspace (not depot). | ||
#6 | 8915 | Paul Allen |
Support for ChangeLog and RepoBrowser. - Added RepoBrowser for Swarm (porting the others should be easy) - ChangeLog XML file now only stores the changelist number all other information is fetched from Perforce |
||
#5 | 8765 | Paul Allen | Update status to include SUBMITTED and sync to change. | ||
#4 | 8762 | Paul Allen |
Console Ouptut logging for SCM build steps. - Removed SLF4J and used old style logger (matching Jenkins) - Set Client Host filed to null, Jenkins sometimes gives an IP address. - Test p4java setps in SCM tasks for success(true/false) |
||
#3 | 8725 | Paul Allen |
Minor fixes: - Improved tidy workspace method - Fix for template clients - After an unshelf revert -k files - Minor bug in CheckoutTask - Clear callback urls to prevet reuse |
||
#2 | 8715 | Paul Allen |
#review-8716 [Basic Swarm-Jenkins cycle DONE] Support Job's build notification and then POST's the pass/fail call-back URLs to Swarm. |
||
#1 | 8694 | Paul Allen | Added support for unshelve and revert -w behaviour for builds. |