Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
df274ee4
Commit
df274ee4
authored
Jan 08, 2020
by
Greg Messner
Browse files
Added support for deleting and keeping job artifacts (#493).
parent
a56573ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/JobApi.java
View file @
df274ee4
...
...
@@ -172,7 +172,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return a single job for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
getJob
(
Object
projectIdOrPath
,
i
nt
jobId
)
throws
GitLabApiException
{
public
Job
getJob
(
Object
projectIdOrPath
,
I
nt
eger
jobId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"jobs"
,
jobId
);
return
(
response
.
readEntity
(
Job
.
class
));
}
...
...
@@ -186,7 +186,7 @@ public class JobApi extends AbstractApi implements Constants {
* @param jobId the job ID to get
* @return a single job for the specified project ID as an Optional intance
*/
public
Optional
<
Job
>
getOptionalJob
(
Object
projectIdOrPath
,
i
nt
jobId
)
{
public
Optional
<
Job
>
getOptionalJob
(
Object
projectIdOrPath
,
I
nt
eger
jobId
)
{
try
{
return
(
Optional
.
ofNullable
(
getJob
(
projectIdOrPath
,
jobId
)));
}
catch
(
GitLabApiException
glae
)
{
...
...
@@ -422,7 +422,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return a String containing the specified job's trace
* @throws GitLabApiException if any exception occurs during execution
*/
public
String
getTrace
(
Object
projectIdOrPath
,
i
nt
jobId
)
throws
GitLabApiException
{
public
String
getTrace
(
Object
projectIdOrPath
,
I
nt
eger
jobId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getDefaultPerPageParam
(),
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"jobs"
,
jobId
,
"trace"
);
return
(
response
.
readEntity
(
String
.
class
));
...
...
@@ -438,7 +438,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return job instance which just canceled
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
cancleJob
(
Object
projectIdOrPath
,
i
nt
jobId
)
throws
GitLabApiException
{
public
Job
cancleJob
(
Object
projectIdOrPath
,
I
nt
eger
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"jobs"
,
jobId
,
"cancel"
);
return
(
response
.
readEntity
(
Job
.
class
));
...
...
@@ -454,7 +454,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return job instance which just retried
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
retryJob
(
Object
projectIdOrPath
,
i
nt
jobId
)
throws
GitLabApiException
{
public
Job
retryJob
(
Object
projectIdOrPath
,
I
nt
eger
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Status
.
CREATED
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"jobs"
,
jobId
,
"retry"
);
return
(
response
.
readEntity
(
Job
.
class
));
...
...
@@ -470,7 +470,7 @@ public class JobApi extends AbstractApi implements Constants {
* @return job instance which just erased
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
eraseJob
(
Object
projectIdOrPath
,
i
nt
jobId
)
throws
GitLabApiException
{
public
Job
eraseJob
(
Object
projectIdOrPath
,
I
nt
eger
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Status
.
CREATED
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"jobs"
,
jobId
,
"erase"
);
return
(
response
.
readEntity
(
Job
.
class
));
...
...
@@ -486,9 +486,38 @@ public class JobApi extends AbstractApi implements Constants {
* @return job instance which just played
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
playJob
(
Object
projectIdOrPath
,
i
nt
jobId
)
throws
GitLabApiException
{
public
Job
playJob
(
Object
projectIdOrPath
,
I
nt
eger
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Status
.
CREATED
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"jobs"
,
jobId
,
"play"
);
return
(
response
.
readEntity
(
Job
.
class
));
}
/**
* Prevents artifacts from being deleted when expiration is set.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/jobs/:job_id/artifacts</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the ID to keep artifacts for
* @return the Job instance that was just modified
* @throws GitLabApiException if any exception occurs during execution
*/
public
Job
keepArtifacts
(
Object
projectIdOrPath
,
Integer
jobId
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
null
;
Response
response
=
post
(
Status
.
CREATED
,
formData
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"jobs"
,
jobId
,
"keep"
);
return
(
response
.
readEntity
(
Job
.
class
));
}
/**
* Delete artifacts of a job.
*
* <pre><code>GitLab Endpoint: DELETE /projects/:id/jobs/:job_id/artifacts</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the ID to delete artifacts for
* @throws GitLabApiException if any exception occurs during execution
*/
public
void
deleteArtifacts
(
Object
projectIdOrPath
,
Integer
jobId
)
throws
GitLabApiException
{
delete
(
Status
.
NO_CONTENT
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"jobs"
,
jobId
,
"artifacts"
);
}
}
src/main/java/org/gitlab4j/api/models/Job.java
View file @
df274ee4
...
...
@@ -27,6 +27,8 @@ public class Job {
private
JobStatus
status
;
private
String
when
;
private
Boolean
manual
;
private
Boolean
allowFailure
;
private
Float
duration
;
public
Integer
getId
()
{
return
id
;
...
...
@@ -188,6 +190,22 @@ public class Job {
this
.
manual
=
manual
;
}
public
Boolean
getAllowFailure
()
{
return
allowFailure
;
}
public
void
setAllowFailure
(
Boolean
allowFailure
)
{
this
.
allowFailure
=
allowFailure
;
}
public
Float
getDuration
()
{
return
duration
;
}
public
void
setDuration
(
Float
duration
)
{
this
.
duration
=
duration
;
}
public
Job
withId
(
Integer
id
)
{
this
.
id
=
id
;
return
this
;
...
...
@@ -273,6 +291,11 @@ public class Job {
return
this
;
}
public
Job
allowFailureManual
(
Boolean
allowFailure
)
{
this
.
allowFailure
=
allowFailure
;
return
this
;
}
@Override
public
String
toString
()
{
return
(
JacksonJson
.
toJsonString
(
this
));
...
...
src/test/resources/org/gitlab4j/api/job.json
View file @
df274ee4
...
...
@@ -35,6 +35,8 @@
"status"
:
"failed"
,
"tag"
:
false
,
"web_url"
:
"https://example.com/foo/bar/-/jobs/7"
,
"allow_failure"
:
false
,
"duration"
:
0.465
,
"user"
:
{
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"created_at"
:
"2015-12-21T13:14:24.077Z"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment