Skip to content

Commit

Permalink
- Merged master from upstream.
Browse files Browse the repository at this point in the history
- Addressed comments in PR
  • Loading branch information
pbendersky committed May 19, 2016
2 parents 3f08ce5 + 54dd74e commit 692a9c3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 29 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/com/dabsquared/gitlabjenkins/GitLabPluginMode.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand All @@ -12,21 +7,4 @@
public enum GitLabPluginMode {
LEGACY,
MODERN;
/*
private final Class<? extends GitLabPluginStrategy> pushTriggerStrategyClass;
GitLabPluginMode(Class<? extends GitLabPluginStrategy> 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;
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public String getMergeRequestDescription() {
public Integer getMergeRequestId() {
return mergeRequestId;
}

public Integer getMergeRequestIid() {
return mergeRequestIid;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 692a9c3

Please sign in to comment.