Skip to content

Commit 5010dc7

Browse files
SammyVimestimols
authored andcommitted
Add ability to run pipelines (similar to webinterface Pipelines -> Run Pipeline) (timols#357)
1 parent 8695064 commit 5010dc7

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

src/main/java/org/gitlab/api/GitlabAPI.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,33 @@ public List<GitlabJob> getProjectJobs(Integer projectId) {
10211021
}
10221022

10231023

1024+
/**
1025+
* Run pipeline for selected project and branch
1026+
* @param project project
1027+
* @param ref branch
1028+
* @param variables pipeline variables
1029+
* @return Created pipeline
1030+
* @throws IOException
1031+
*/
1032+
public GitlabPipeline runPipeline(GitlabProject project, String ref, List<GitlabBuildVariable> variables) throws IOException {
1033+
return runPipeline(project.getId(), ref, variables);
1034+
}
1035+
1036+
1037+
/**
1038+
* Run pipeline for selected project and branch
1039+
* @param projectId project's id
1040+
* @param ref branch
1041+
* @param variables pipeline variables
1042+
* @return Created pipeline
1043+
* @throws IOException
1044+
*/
1045+
public GitlabPipeline runPipeline(Integer projectId, String ref, List<GitlabBuildVariable> variables) throws IOException {
1046+
Query query = new Query().appendIf("ref", ref);
1047+
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabPipeline.CREATE_URL + query.toString();
1048+
return dispatch().with("variables", variables).to(tailUrl, GitlabPipeline.class);
1049+
}
1050+
10241051
/**
10251052
* Gets a list of project's jobs of the given pipeline in Gitlab
10261053
*

src/main/java/org/gitlab/api/models/GitlabBuildVariable.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ public GitlabBuildVariable() {
1414
public GitlabBuildVariable(String key, String value) {
1515
this.key = key;
1616
this.value = value;
17+
this.variableType = VariableType.env_var;
18+
}
19+
20+
public GitlabBuildVariable(String key, String value, VariableType variableType) {
21+
this.key = key;
22+
this.value = value;
23+
this.variableType = variableType;
1724
}
1825

1926
@JsonProperty("key")
@@ -22,6 +29,9 @@ public GitlabBuildVariable(String key, String value) {
2229
@JsonProperty("value")
2330
private String value;
2431

32+
@JsonProperty("variable_type")
33+
private VariableType variableType;
34+
2535
public String getKey() {
2636
return key;
2737
}
@@ -37,4 +47,18 @@ public String getValue() {
3747
public void setValue(String value) {
3848
this.value = value;
3949
}
50+
51+
public VariableType getVariableType() {
52+
return variableType;
53+
}
54+
55+
public void setVariableType(VariableType variableType) {
56+
this.variableType = variableType;
57+
}
58+
59+
public enum VariableType {
60+
env_var,
61+
file
62+
}
63+
4064
}

src/main/java/org/gitlab/api/models/GitlabPipeline.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
public class GitlabPipeline {
1010
public static final String URL = "/pipelines";
1111

12+
public static final String CREATE_URL = "/pipeline";
13+
14+
1215
@JsonProperty("id")
1316
private Integer id;
1417

0 commit comments

Comments
 (0)