Got the base request working.
This commit is contained in:
parent
8802f5a6d8
commit
f390fd068a
|
@ -9,14 +9,52 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
|
<excludeFolder url="file://$MODULE_DIR$/target/classes" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target/generated-sources/groovy-stubs" />
|
<excludeFolder url="file://$MODULE_DIR$/target/generated-sources/groovy-stubs" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target/inject-tests" />
|
<excludeFolder url="file://$MODULE_DIR$/target/work" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target/jenkins-for-test" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target/surefire" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target/surefire-reports" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
|
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jgit:org.eclipse.jgit:0.12.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.jcraft:jsch:0.1.44-1" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.apache.httpcomponents:httpclient:4.2.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-logging:commons-logging:1.1.3" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-codec:commons-codec:1.8" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main:jenkins-war:war:1.564" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jenkins-ci.main:jenkins-core:1.564" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jenkins-ci.main:remoting:2.41" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jenkins-ci.main:cli:1.564" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-io:commons-io:2.4" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.kohsuke.stapler:stapler-groovy:1.224" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.kohsuke.stapler:stapler-jelly:1.224" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.kohsuke.stapler:stapler:1.224" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: com.jcraft:jzlib:1.1.3-kohsuke-1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.kohsuke.stapler:stapler-jrebel:1.224" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.kohsuke.stapler:stapler-adjunct-codemirror:1.3" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jenkins-ci:bytecode-compatibility-transformer:1.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.kohsuke:asm5:5.0.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jenkins-ci:task-reactor:1.4" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jvnet.hudson:xstream:1.4.7-jenkins-1" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jvnet.winp:winp:1.19" level="project" />
|
||||||
|
<orderEntry type="library" scope="PROVIDED" name="Maven: org.samba.jcifs:jcifs:1.2.19" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main:jenkins-test-harness:1.564" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main:jenkins-war:war-for-test:1.564" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.modules:instance-identity:1.4" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.modules:slave-installer:1.3" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.modules:windows-slave-installer:1.4" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.modules:systemd-slave-installer:1.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:slf4j-jdk14:1.7.7" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:slf4j-api:1.7.7" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main:maven-plugin:2.3" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.plugins:mailer:1.8" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main.maven:maven-agent:1.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main.maven:maven-interceptor:1.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main.maven:maven3-agent:1.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main.maven:maven31-agent:1.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main.maven:maven3-interceptor:1.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main.maven:maven3-interceptor-commons:1.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.main.maven:maven31-interceptor:1.5" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.plugins:matrix-auth:1.0.2" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.plugins:antisamy-markup-formatter:1.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.jenkins-ci.plugins:matrix-project:1.0-beta-1" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.jenkins-ci.plugins:git:2.2.1" level="project" />
|
<orderEntry type="library" name="Maven: org.jenkins-ci.plugins:git:2.2.1" level="project" />
|
||||||
<orderEntry type="library" name="Maven: org.eclipse.jgit:org.eclipse.jgit:0.12.1" level="project" />
|
<orderEntry type="library" name="Maven: org.eclipse.jgit:org.eclipse.jgit:0.12.1" level="project" />
|
||||||
<orderEntry type="library" name="Maven: com.jcraft:jsch:0.1.44-1" level="project" />
|
<orderEntry type="library" name="Maven: com.jcraft:jsch:0.1.44-1" level="project" />
|
||||||
|
|
|
@ -5,6 +5,7 @@ import hudson.Util;
|
||||||
import hudson.console.AnnotatedLargeText;
|
import hudson.console.AnnotatedLargeText;
|
||||||
import hudson.model.AbstractProject;
|
import hudson.model.AbstractProject;
|
||||||
import hudson.model.Action;
|
import hudson.model.Action;
|
||||||
|
import hudson.model.Hudson;
|
||||||
import hudson.model.Item;
|
import hudson.model.Item;
|
||||||
import hudson.plugins.git.RevisionParameterAction;
|
import hudson.plugins.git.RevisionParameterAction;
|
||||||
import hudson.triggers.SCMTrigger;
|
import hudson.triggers.SCMTrigger;
|
||||||
|
@ -17,6 +18,9 @@ import hudson.util.StreamTaskListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -28,6 +32,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import jenkins.model.Jenkins;
|
import jenkins.model.Jenkins;
|
||||||
|
import jenkins.model.JenkinsLocationConfiguration;
|
||||||
import org.kohsuke.stapler.DataBoundConstructor;
|
import org.kohsuke.stapler.DataBoundConstructor;
|
||||||
|
|
||||||
import jenkins.model.Jenkins.MasterComputer;
|
import jenkins.model.Jenkins.MasterComputer;
|
||||||
|
@ -45,6 +50,7 @@ public class GitLabPushTrigger extends Trigger<AbstractProject<?, ?>> {
|
||||||
|
|
||||||
@DataBoundConstructor
|
@DataBoundConstructor
|
||||||
public GitLabPushTrigger() {
|
public GitLabPushTrigger() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPost(final GitLabPushRequest req) {
|
public void onPost(final GitLabPushRequest req) {
|
||||||
|
@ -137,7 +143,7 @@ public class GitLabPushTrigger extends Trigger<AbstractProject<?, ?>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIconFileName() {
|
public String getIconFileName() {
|
||||||
return "/plugin/gitlab/images/24x24/gitlab-log.png";
|
return "/plugin/gitlab-jenkins/images/24x24/gitlab.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
|
@ -189,16 +195,41 @@ public class GitLabPushTrigger extends Trigger<AbstractProject<?, ?>> {
|
||||||
@Extension
|
@Extension
|
||||||
public static class DescriptorImpl extends TriggerDescriptor {
|
public static class DescriptorImpl extends TriggerDescriptor {
|
||||||
|
|
||||||
|
AbstractProject project;
|
||||||
|
|
||||||
private transient final SequentialExecutionQueue queue = new SequentialExecutionQueue(Jenkins.MasterComputer.threadPoolForRemoting);
|
private transient final SequentialExecutionQueue queue = new SequentialExecutionQueue(Jenkins.MasterComputer.threadPoolForRemoting);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(Item item) {
|
public boolean isApplicable(Item item) {
|
||||||
return item instanceof AbstractProject;
|
if(item instanceof AbstractProject) {
|
||||||
|
project = (AbstractProject) item;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return "Build when a change is pushed to GitLab";
|
if(project == null) {
|
||||||
|
return "Build when a change is pushed to GitLab, unknown URL";
|
||||||
|
}
|
||||||
|
|
||||||
|
String projectURL = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
projectURL = URLEncoder.encode(project.getName(), "UTF-8");
|
||||||
|
projectURL = projectURL.replace("+", "%20");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
projectURL = project.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Build when a change is pushed to GitLab with this url: JENKINS_HOST/projects/" + projectURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getHelpFile() {
|
||||||
|
return "/plugin/gitlab-jenkins/help/help-trigger.jelly";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DescriptorImpl get() {
|
public static DescriptorImpl get() {
|
||||||
|
|
|
@ -27,11 +27,9 @@ import java.util.logging.Logger;
|
||||||
* @author Daniel Brooks
|
* @author Daniel Brooks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Extension
|
|
||||||
public class GitLabWebHook implements UnprotectedRootAction {
|
public class GitLabWebHook implements UnprotectedRootAction {
|
||||||
|
|
||||||
public static final String WEBHOOK_URL = "gitlab-webhook";
|
public static final String WEBHOOK_URL = "projects";
|
||||||
|
|
||||||
|
|
||||||
public String getIconFileName() {
|
public String getIconFileName() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -45,7 +43,7 @@ public class GitLabWebHook implements UnprotectedRootAction {
|
||||||
return WEBHOOK_URL;
|
return WEBHOOK_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequirePOST
|
//@RequirePOST For some reason the RequirePost is not working right.
|
||||||
public void doIndex(StaplerRequest req) {
|
public void doIndex(StaplerRequest req) {
|
||||||
LOGGER.log(Level.FINE, "WebHook called.");
|
LOGGER.log(Level.FINE, "WebHook called.");
|
||||||
|
|
||||||
|
@ -63,13 +61,14 @@ public class GitLabWebHook implements UnprotectedRootAction {
|
||||||
JSONObject json = JSONObject.fromObject(payload);
|
JSONObject json = JSONObject.fromObject(payload);
|
||||||
LOGGER.log(Level.FINE, "payload: {0}", json.toString(4));
|
LOGGER.log(Level.FINE, "payload: {0}", json.toString(4));
|
||||||
|
|
||||||
GitLabPushRequest req = GitLabPushRequest.create(json);
|
//Eventually parse the request here.
|
||||||
|
// GitLabPushRequest req = GitLabPushRequest.create(json);
|
||||||
String repositoryUrl = req.getRepository().getUrl();
|
//
|
||||||
if (repositoryUrl == null) {
|
// String repositoryUrl = req.getRepository().getUrl();
|
||||||
LOGGER.log(Level.WARNING, "No repository url found.");
|
// if (repositoryUrl == null) {
|
||||||
return;
|
// LOGGER.log(Level.WARNING, "No repository url found.");
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
Authentication old = SecurityContextHolder.getContext().getAuthentication();
|
Authentication old = SecurityContextHolder.getContext().getAuthentication();
|
||||||
SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
|
SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
|
||||||
|
@ -77,11 +76,13 @@ public class GitLabWebHook implements UnprotectedRootAction {
|
||||||
for (AbstractProject<?, ?> job : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
|
for (AbstractProject<?, ?> job : Jenkins.getInstance().getAllItems(AbstractProject.class)) {
|
||||||
GitLabPushTrigger trigger = job.getTrigger(GitLabPushTrigger.class);
|
GitLabPushTrigger trigger = job.getTrigger(GitLabPushTrigger.class);
|
||||||
if (trigger == null) {
|
if (trigger == null) {
|
||||||
|
//This job does not have the Gitlab Trigger Enabled so skip it.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//if (RepositoryUrlCollector.collect(job).contains(repositoryUrl.toLowerCase())) {
|
|
||||||
trigger.onPost(req);
|
//Here we trigger the ush
|
||||||
//}
|
//trigger.onPost(req);
|
||||||
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
SecurityContextHolder.getContext().setAuthentication(old);
|
SecurityContextHolder.getContext().setAuthentication(old);
|
||||||
|
@ -89,27 +90,6 @@ public class GitLabWebHook implements UnprotectedRootAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Extension
|
|
||||||
public static class GitLabWebHookCrumbExclusion extends CrumbExclusion {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws IOException, ServletException {
|
|
||||||
String pathInfo = req.getPathInfo();
|
|
||||||
LOGGER.log(Level.FINE, "path: {0}", pathInfo);
|
|
||||||
|
|
||||||
if (pathInfo != null && pathInfo.equals(getExclusionPath())) {
|
|
||||||
chain.doFilter(req, resp);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getExclusionPath() {
|
|
||||||
return '/' + WEBHOOK_URL + '/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(GitLabWebHook.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(GitLabWebHook.class.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
Configure GitLab to deliver a POST request to your Jenkins like GitLab CI.
|
||||||
|
</div>
|
Binary file not shown.
After Width: | Height: | Size: 7.3 KiB |
Loading…
Reference in New Issue