Finsihing up 1.0
This commit is contained in:
parent
62bde3e036
commit
0c511bb99f
38
README.md
38
README.md
|
@ -15,11 +15,42 @@ Current Supported GitLabCI Functions
|
|||
* `/project/PROJECT_NAME/builds/COMMIT_SHA1` redirects to build page.
|
||||
|
||||
|
||||
* `/project/PROJECT_NAME/build` In order for it to build properly on push you need to add this as a seperate web hook. For some reason GitLab is not sending the webhook.
|
||||
* `/project/PROJECT_NAME` In order for it to build properly on push you need to add this as a seperate web hook for just merge requests.
|
||||
|
||||
Major Help Needed
|
||||
=====================
|
||||
I would like this project to be able to handle building merge requests and regular pushes. In order to do this I need a way to configure the git plugin via code to merge two branches together before a build. Much like the RevisionParameterAction.java in the git plugin, we need a class that takes to branches, a source and a target, and can be passed as a build action. I have started an issue for the Git plugin here: https://issues.jenkins-ci.org/browse/JENKINS-23362 If you know of a way to do this please PM on twitter at @bass_rock. All the other necessary code exists in this repo and works. We just need the merge requests to work and we can put a V1.0 on this thing!
|
||||
I would like this project to be able to handle building merge requests and regular pushes. In order to do this I need a way to configure the git plugin via code to merge two branches together before a build. Much like the RevisionParameterAction.java in the git plugin, we need a class that takes to branches, a source and a target, and can be passed as a build action. I have started an issue for the Git plugin here: https://issues.jenkins-ci.org/browse/JENKINS-23362 If you know of a way to do this please PM on twitter at @bass_rock. All the other necessary code exists in this repo and works.
|
||||
|
||||
Using it With A Job
|
||||
=====================
|
||||
* Create a new job by going to ``New Job``
|
||||
* Set the ``Project Name``
|
||||
* Feel free to specify the ``GitHub Project`` url as the url for the Gitlab project (if you have the GitHub plugin installed)
|
||||
* In the ``Source Code Management`` section:
|
||||
* Click ``Git`` and enter your Repositroy URL and in Advanced set its Name to ``origin``
|
||||
* In ``Branch Specifier`` enter ``origin/${sourceBranch}``
|
||||
* In the ``Additional Behaviours`` section:
|
||||
* Click the ``Add`` drop down button and the ``Merge before build`` item
|
||||
* Specify the name of the repository as ``origin`` (if origin corresponds to Gitlab) and enter the ``Branch to merge to`` as ``${targetBranch}``
|
||||
* In the ``Build Triggers`` section:
|
||||
* Check the ``Build when a change is pushed to GitLab.``
|
||||
* In GitLab go to the project ``Settings``
|
||||
* Click on ``Services``
|
||||
* Click on ``GitLab CI``
|
||||
* For ``token`` put any random string (This is not yet functioning)
|
||||
* For ``Project URL`` put ``http://JENKINS_URL/project/PROJECT_NAME``
|
||||
* Click on ``Web Hooks``
|
||||
* Add a ``Web Hook`` for ``Merge Request Events`` to ``http://JENKINS_URL/project/PROJECT_NAME`` (GitLab for some reason does not send a merge request event with the GitLab Service)
|
||||
* Configure any other pre build, build or post build actions as necessary
|
||||
* ``Save`` to preserve your changes
|
||||
|
||||
You can trigger a job a manually by clicking ``This build is parameterized`` and adding the relevant build parameters.
|
||||
These include:
|
||||
|
||||
* sourceBranch
|
||||
* targetBranch
|
||||
* branch (This is optional and can be used in shell scripts for the branch being built by the push request)
|
||||
|
||||
|
||||
Help Needed
|
||||
=====================
|
||||
|
@ -46,5 +77,6 @@ Contributing
|
|||
Contributors
|
||||
=====================
|
||||
|
||||
* @bass_rock, base ground work.
|
||||
* @bass_rock, base ground work, primary developer.
|
||||
* @DABSquared, company sponsoring development.
|
||||
* @xaniasd, suggested a temporary work around for merge requests on Gitter.
|
||||
|
|
Binary file not shown.
|
@ -26,7 +26,6 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/target/jenkins-for-test" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target/surefire-reports" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target/work" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
|
|
@ -28,7 +28,7 @@ public class GitLabMergeCause extends SCMTrigger.SCMTriggerCause {
|
|||
|
||||
@Override
|
||||
public String getShortDescription() {
|
||||
return "Gitlab Merge Request #" + this.mergeRequest.getObjectAttribute().getId() + " : " + this.mergeRequest.getObjectAttribute().getSourceBranch() +
|
||||
return "GitLab Merge Request #" + this.mergeRequest.getObjectAttribute().getId() + " : " + this.mergeRequest.getObjectAttribute().getSourceBranch() +
|
||||
" => " + this.mergeRequest.getObjectAttribute().getTargetBranch();
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,62 @@ public class GitLabPushRequest {
|
|||
this.repository = repository;
|
||||
}
|
||||
|
||||
public Integer getTotalCommitsCount() {
|
||||
return totalCommitsCount;
|
||||
}
|
||||
|
||||
public void setTotalCommitsCount(Integer totalCommitsCount) {
|
||||
this.totalCommitsCount = totalCommitsCount;
|
||||
}
|
||||
|
||||
public String getBefore() {
|
||||
return before;
|
||||
}
|
||||
|
||||
public void setBefore(String before) {
|
||||
this.before = before;
|
||||
}
|
||||
|
||||
public String getAfter() {
|
||||
return after;
|
||||
}
|
||||
|
||||
public void setAfter(String after) {
|
||||
this.after = after;
|
||||
}
|
||||
|
||||
public String getRef() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
public void setRef(String ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public Integer getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public void setProjectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
|
|
|
@ -79,13 +79,23 @@ public class GitLabPushTrigger extends Trigger<AbstractProject<?, ?>> {
|
|||
private Action[] createActions(GitLabPushRequest req) {
|
||||
ArrayList<Action> actions = new ArrayList<Action>();
|
||||
|
||||
String[] branches = req.getRef().split("/");
|
||||
|
||||
String branch = branches[branches.length-1];
|
||||
|
||||
LOGGER.log(Level.INFO, "GitLab Push Request from branch {0}.", branch);
|
||||
|
||||
|
||||
GitSCM scm = (GitSCM) job.getScm();
|
||||
|
||||
BranchSpec spec = scm.getBranches().get(0);
|
||||
String randomBranchName = spec.getName();
|
||||
|
||||
Map<String, ParameterValue> values = new HashMap<String, ParameterValue>();
|
||||
values.put("sourceBranch", new StringParameterValue("sourceBranch", randomBranchName));
|
||||
values.put("targetBranch", new StringParameterValue("targetBranch", randomBranchName));
|
||||
values.put("branch", new StringParameterValue("branch", branch));
|
||||
|
||||
List<ParameterValue> listValues = new ArrayList<ParameterValue>(values.values());
|
||||
|
||||
ParametersAction parametersAction = new ParametersAction(listValues);
|
||||
|
|
|
@ -157,7 +157,7 @@ public class GitLabWebHook implements UnprotectedRootAction {
|
|||
|
||||
if(mainBuild == null) {
|
||||
try {
|
||||
object.put("status", "unknown");
|
||||
object.put("status", "pending");
|
||||
this.writeJSON(rsp, object);
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
|
|
Loading…
Reference in New Issue