package org.jenkinsci.plugins.p4.swarmAPI; import com.google.gson.Gson; import hudson.Extension; import hudson.model.RootAction; import jenkins.branch.BranchSource; import jenkins.model.Jenkins; import org.jenkinsci.Symbol; import org.jenkinsci.plugins.p4.client.ConnectionHelper; import org.jenkinsci.plugins.p4.populate.AutoCleanImpl; import org.jenkinsci.plugins.p4.scm.SwarmScmSource; import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import javax.servlet.ServletException; import java.io.IOException; import java.io.PrintWriter; import java.util.List; @Symbol("swarm_projects") @Extension public class SwarmQueryAction implements RootAction { @Override public String getIconFileName() { return null; } @Override public String getDisplayName() { return null; } @Override public String getUrlName() { return "swarm"; } public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { String path = req.getRestOfPath(); if (path != null && path.startsWith("/project")) { String credentialID = req.getParameter("credential"); try (ConnectionHelper p4 = new ConnectionHelper(credentialID, null)) { SwarmHelper swarm = new SwarmHelper(p4, "4"); List<String> list = swarm.getProjects(); Gson gson = new Gson(); String json = gson.toJson(list); PrintWriter out = rsp.getWriter(); out.write(json); } catch (Exception e) { throw new IOException(e); } } if (path != null && path.startsWith("/create")) { String credentialID = req.getParameter("credential"); String project = req.getParameter("project"); String name = req.getParameter("name"); if (name == null || name.isEmpty()) { name = project; } try (ConnectionHelper p4 = new ConnectionHelper(credentialID, null)) { SwarmHelper swarm = new SwarmHelper(p4, "4"); String format = "jenkins-${NODE_NAME}-${JOB_NAME}"; SwarmScmSource source = new SwarmScmSource(credentialID, null, format); source.setProject(project); source.setSwarm(swarm); source.setPopulate(new AutoCleanImpl()); WorkflowMultiBranchProject multi = Jenkins.getInstance().createProject(WorkflowMultiBranchProject.class, name); multi.getSourcesList().add(new BranchSource(source)); multi.scheduleBuild2(0); } catch (Exception e) { throw new IOException(e); } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 30143 | Sandeep Kumar |
Merge pull request #[197] from [skumar7322/SwarmAPI] Change Swarm API version to v11 |
||
#7 | 27770 | Paul Allen | Update Swarm API to v9 | ||
#6 | 26673 | Paul Allen |
Code cleanup - remove calls to Deprecated methods - Deprecated classes like AbstractStepImpl, AbstractStepDescriptorImpl and AbstractSynchronousStepExecution for P4TaggingStep |
||
#5 | 25648 | Paul Allen | BlueOcean: Change responce to application/json | ||
#4 | 25642 | Paul Allen | BlueOcean: return error 400 on Create if Pipeline exists. | ||
#3 | 25640 | Paul Allen | BlueOcean: create POST call returns Job name. | ||
#2 | 25628 | Paul Allen |
BlueOcean support to create MultiBranch Pipelines. Add filter for Swarm Project list. |
||
#1 | 25624 | Paul Allen |
Swarm project query endpoint for BlueOcean support. For example: GET request on http://localhost:8080/swarm/projects/?credential=myid returns a JSON list of Swarm project IDs: |