diff --git a/README.md b/README.md index bd7a92c08..4080b4f59 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,11 @@ - [Parameterized builds](#parameterized-builds) - [Branch filtering](#branch-filtering) - [Build Tags](#build-tags) +<<<<<<< HEAD - [Contributing to the Plugin](#contributing-to-the-plugin) +======= +- [Parameterized builds](#parameterized-builds) +>>>>>>> master - [Quick test environment setup using Docker](#quick-test-environment-setup-using-docker) - [Access GitLab](#access-gitlab) - [Access Jenkins](#access-jenkins) @@ -128,7 +132,13 @@ You can trigger a build manually from Jenkins. By default, it will fetch from `o * Set *Name of the repository" to ``origin`` * Set *Branch to merge* as ``${gitlabTargetBranch}`` +<<<<<<< HEAD #### Git configuration for Pipeline/Workflow jobs +======= +**Note:** Since version **1.2.0** the *gitlab-plugin* sets the gitlab hook values through *environment variables* instead of *build parameters*. To set default values, consult [EnvInject Plugin](https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin). + +### Git configuration for Pipeline/Workflow jobs +>>>>>>> master **Incompatibility note:** When upgrading to version 1.2.1 or later of the plugin, if you are using Pipeline jobs you will need to manually reconfigure your Pipeline scripts. In older versions the plugin set global Groovy variables that could be accessed as e.g. ${gitlabSourceBranch}. After version 1.2.1, these variables are only accessible in the env[] map. E.g. ${env.gitlabSourceBranch}. * A Jenkins Pipeline bug will prevent the Git clone from working when you use a Pipeline script from SCM. It works if you use the Jenkins job config UI to edit the script. There is a workaround mentioned here: https://issues.jenkins-ci.org/browse/JENKINS-33719 @@ -197,7 +207,25 @@ In addition, you will need to make sure that the Git plugin has an appropriate s 1. Click on Manage Jenkins, then Configure System 2. Under the Git Plugin section, set something for 'Global Config user.name Value' and 'Global Config user.email Value' +<<<<<<< HEAD ### Parameterized builds +======= +# Branch filtering + +Triggers may be filtered based on the branch name, i.e. the build will only be allowed for selected branches. On the project configuration page, when you configure the GitLab trigger, you can choose 'Filter branches by name' or 'Filter branches by regex.' Filter by name takes comma-separated lists of branch names to include and/or exclude from triggering a build. Filter by regex takes a Java regular expression to include and/or exclude. + +**Note:** This functionality requires accessing the GitLab server (see [above](#configuring-access-to-gitlab)) and for the time being also a git repository url already saved in the project configuration. In other words, when creating a new project, the configuration needs to be saved *once* before being able to select the allowed branches. For Workflow/Pipeline jobs, the configuration must be saved *and* the job must be run once before the list is populated. For existing projects, all branches are allowed to push by default. + +# Build Tags + +In order to build when a new tag is pushed: +* In the ``GitLab server`` add ``Tag push events`` to the ``Web Hook`` +* In the ``Jenkins`` under the ``Source Code Management`` section: + * select ``Advance...`` and add ``+refs/tags/*:refs/remotes/origin/tags/*`` as ``Refspec`` + * you can also use ``Branch Specifier`` to specify which tag need to be built (exampple ``refs/tags/${TAGNAME}``) + +# Parameterized builds +>>>>>>> master You can trigger a job a manually by clicking ``This build is parameterized`` and adding the any of the relevant build parameters. These include: diff --git a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPluginMode.java b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPluginMode.java index 4375abdff..306e79d3f 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/GitLabPluginMode.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/GitLabPluginMode.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.dabsquared.gitlabjenkins; /** @@ -12,21 +7,4 @@ public enum GitLabPluginMode { LEGACY, MODERN; -/* - private final Class pushTriggerStrategyClass; - - GitLabPluginMode(Class pushTriggerStrategyClass) { - this.pushTriggerStrategyClass = pushTriggerStrategyClass; - } - - public GitLabPluginStrategy getGitLabPluginStrategy() { - try { - return this.pushTriggerStrategyClass.newInstance(); - } catch (InstantiationException | IllegalAccessException ex) { - Logger.getLogger(GitLabPluginMode.class.getName()).log(Level.SEVERE, null, ex); - } - - return null; - } -*/ } diff --git a/src/main/java/com/dabsquared/gitlabjenkins/cause/CauseData.java b/src/main/java/com/dabsquared/gitlabjenkins/cause/CauseData.java index c14f9df49..6cab5dc85 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/cause/CauseData.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/cause/CauseData.java @@ -152,7 +152,7 @@ public String getMergeRequestDescription() { public Integer getMergeRequestId() { return mergeRequestId; } - + public Integer getMergeRequestIid() { return mergeRequestIid; } diff --git a/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/AbstractMergeRequestHookTriggerHandler.java b/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/AbstractMergeRequestHookTriggerHandler.java index 3222cd7b1..03fc846fa 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/AbstractMergeRequestHookTriggerHandler.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/trigger/handler/merge/AbstractMergeRequestHookTriggerHandler.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.dabsquared.gitlabjenkins.trigger.handler.merge; import com.dabsquared.gitlabjenkins.cause.CauseData; diff --git a/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java b/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java index 4e0252d15..50fb5833f 100644 --- a/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java +++ b/src/main/java/com/dabsquared/gitlabjenkins/util/CommitStatusUpdater.java @@ -66,7 +66,9 @@ private static void printf(TaskListener listener, String message, Object... args } private static String getBuildRevision(Run build) { - return build.getAction(BuildData.class).getLastBuiltRevision().getSha1String(); + BuildData action = build.getAction(BuildData.class); + + return action.getLastBuild(action.getLastBuiltRevision().getSha1()).getMarked().getSha1String(); } private static boolean existsCommit(GitLabApi client, String gitlabProjectId, String commitHash) { diff --git a/src/test/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisherTest.java b/src/test/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisherTest.java index 28869ced4..b60601786 100644 --- a/src/test/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisherTest.java +++ b/src/test/java/com/dabsquared/gitlabjenkins/publisher/GitLabCommitStatusPublisherTest.java @@ -19,9 +19,11 @@ import hudson.model.StreamBuildListener; import hudson.model.TaskListener; import hudson.plugins.git.Revision; +import hudson.plugins.git.util.Build; import hudson.plugins.git.util.BuildData; import hudson.util.Secret; import jenkins.model.Jenkins; +import org.eclipse.jgit.lib.ObjectId; import org.hamcrest.CoreMatchers; import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl; import org.junit.After; @@ -234,6 +236,10 @@ private AbstractBuild mockBuild(String sha, String buildUrl, String gitLabConnec when(buildData.getLastBuiltRevision()).thenReturn(revision); when(build.getCause(GitLabWebHookCause.class)).thenReturn(cause); when(cause.getData()).thenReturn(causeData); + when(buildData.getRemoteUrls()).thenReturn(new HashSet<>(Arrays.asList(sourceRepoUrl, targetRepoUrl))); + Build gitBuild = mock(Build.class); + when(gitBuild.getMarked()).thenReturn(revision); + when(buildData.getLastBuild(any(ObjectId.class))).thenReturn(gitBuild); when(build.getAction(BuildData.class)).thenReturn(buildData); when(build.getResult()).thenReturn(result); when(build.getUrl()).thenReturn(buildUrl);