Add updateGitlabCommitStatus step for setting a custom build state for a commit
This commit is contained in:
parent
2aa01588a3
commit
4e116ab2ee
10
README.md
10
README.md
|
@ -145,6 +145,16 @@ GitLab 8.1 has implemented a commit status api, you need an extra post-build ste
|
|||
}
|
||||
}
|
||||
```
|
||||
* For pipeline jobs there is also the updateGitlabCommitStatus step to use a custom state for updating the commit status:
|
||||
|
||||
```
|
||||
node() {
|
||||
stage 'Checkout'
|
||||
checkout <your-scm-config>
|
||||
|
||||
updateGitlabCommitStatus name: 'build', state: 'pending'
|
||||
}
|
||||
```
|
||||
* Configure access to GitLab as described above in "Configure access to GitLab" (the account needs at least developer permissions to post commit statuses)
|
||||
|
||||
# Branch filtering
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package com.dabsquared.gitlabjenkins.workflow;
|
||||
|
||||
import com.dabsquared.gitlabjenkins.gitlab.api.model.BuildState;
|
||||
import com.dabsquared.gitlabjenkins.util.CommitStatusUpdater;
|
||||
import hudson.Extension;
|
||||
import hudson.model.Run;
|
||||
import hudson.util.ListBoxModel;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl;
|
||||
import org.jenkinsci.plugins.workflow.steps.AbstractStepImpl;
|
||||
import org.jenkinsci.plugins.workflow.steps.AbstractSynchronousStepExecution;
|
||||
import org.jenkinsci.plugins.workflow.steps.StepContextParameter;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
import org.kohsuke.stapler.export.ExportedBean;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.EnumSet;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:robin.mueller@1und1.de">Robin Müller</a>
|
||||
*/
|
||||
@ExportedBean
|
||||
public class UpdateGitLabCommitStatusStep extends AbstractStepImpl {
|
||||
|
||||
private String name;
|
||||
private BuildState state;
|
||||
|
||||
@DataBoundConstructor
|
||||
public UpdateGitLabCommitStatusStep(String name, BuildState state) {
|
||||
this.name = StringUtils.isEmpty(name) ? null : name;
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public BuildState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public static class Execution extends AbstractSynchronousStepExecution<Void> {
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
@StepContextParameter
|
||||
private transient Run<?, ?> run;
|
||||
|
||||
@Inject
|
||||
private transient UpdateGitLabCommitStatusStep step;
|
||||
|
||||
@Override
|
||||
protected Void run() throws Exception {
|
||||
final String name = StringUtils.isEmpty(step.name) ? "jenkins" : step.name;
|
||||
CommitStatusUpdater.updateCommitStatus(run, null, step.state, name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static final class DescriptorImpl extends AbstractStepDescriptorImpl {
|
||||
public DescriptorImpl() {
|
||||
super(Execution.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Update the commit status in GitLab";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionName() {
|
||||
return "updateGitlabCommitStatus";
|
||||
}
|
||||
|
||||
public ListBoxModel doFillStateItems() {
|
||||
ListBoxModel options = new ListBoxModel();
|
||||
for (BuildState buildState : EnumSet.allOf(BuildState.class)) {
|
||||
options.add(buildState.name());
|
||||
}
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?jelly escape-by-default='true'?>
|
||||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
|
||||
<f:entry title="${%Build name}" field="name" help="/plugin/gitlab-plugin/help/help-buildName.html">
|
||||
<f:textbox default="jenkins"/>
|
||||
</f:entry>
|
||||
<f:entry title="${%Build state}" field="state">
|
||||
<f:select/>
|
||||
</f:entry>
|
||||
</j:jelly>
|
Loading…
Reference in New Issue