forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipelineState.java
More file actions
72 lines (66 loc) · 1.99 KB
/
PipelineState.java
File metadata and controls
72 lines (66 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package io.jenkins.plugins.pipelinegraphview.utils;
import com.fasterxml.jackson.annotation.JsonValue;
import hudson.model.Result;
import java.util.Locale;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
public enum PipelineState {
// BlueRunState
QUEUED,
RUNNING,
PAUSED,
SKIPPED,
NOT_BUILT,
FINISHED,
// BlueRunResult
SUCCESS,
UNSTABLE,
FAILURE,
UNKNOWN,
ABORTED;
public boolean isInProgress() {
return this == RUNNING || this == QUEUED || this == PAUSED;
}
public static PipelineState of(WorkflowRun run) {
Result result = run.getResult();
if (result == Result.SUCCESS) {
return SUCCESS;
} else if (result == Result.UNSTABLE) {
return UNSTABLE;
} else if (result == Result.FAILURE) {
return FAILURE;
} else if (result == Result.NOT_BUILT) {
return NOT_BUILT;
} else if (result == Result.ABORTED) {
return ABORTED;
} else if (run.isInProgress()) {
return RUNNING;
} else {
return UNKNOWN;
}
}
public static PipelineState of(NodeRunStatus status) {
if (status.getState() == BlueRun.BlueRunState.FINISHED) {
return switch (status.getResult()) {
case SUCCESS -> SUCCESS;
case UNSTABLE -> UNSTABLE;
case FAILURE -> FAILURE;
case NOT_BUILT -> NOT_BUILT;
case UNKNOWN -> UNKNOWN;
case ABORTED -> ABORTED;
};
}
return switch (status.getState()) {
case QUEUED -> QUEUED;
case RUNNING -> RUNNING;
case PAUSED -> PAUSED;
case SKIPPED -> SKIPPED;
case NOT_BUILT -> NOT_BUILT;
case FINISHED -> FINISHED; // not reached but required for compiler
};
}
@JsonValue
@Override
public String toString() {
return name().toLowerCase(Locale.ROOT);
}
}