-
Notifications
You must be signed in to change notification settings - Fork 10
AGDIGGER-59 trigger jenkins job #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AGDIGGER-59 trigger jenkins job #2
Conversation
I tested it like this:
Please note that we use some features in Jenkins-Java-client 3.7-SNAPSHOT.
|
<groupId>com.offbytwo.jenkins</groupId> | ||
<artifactId>jenkins-client</artifactId> | ||
<version>0.3.6</version> | ||
<version>0.3.7-SNAPSHOT</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do they have a CI running somewhere, where we can suck down the dependency ?
Not a blocker - just asking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matzew good point!
I looked now, but couldn't find anything. I checked the pom.xml files in the source code to see some repository reference. There is one, but that's not the snapshot repository.
No mention of CI.
@khmarbaise Where can we suck Jenkins-Java-client SNAPSHOT? Unfortunately, I haven't still got the approval to post to mailing list (https://groups.google.com/d/forum/java-client-api).
As a quick introduction: we are building a mobile application build farm on top of Jenkins 😎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
asked in mailing list: https://groups.google.com/forum/#!topic/java-client-api/boD3H2KCdFg
LOG.debug("Exception while connecting to Jenkins", e); | ||
throw new DiggerClientException(e); | ||
} catch (InterruptedException e) { | ||
LOG.debug("Exception while sleeping between checks", e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rephrase: "Exception while sleeping between checks" - It's not clear what that means for me.
|
||
if (queueItem.isCancelled()) { | ||
LOG.debug("Queue item is cancelled. Returning -1"); | ||
return -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not like this because we introducing magic number and missing actual problem here.
Best to introduce some object (model) that would contain build number + some info about this build. If something is wrong build number would be empty.
Alternative is to use Long and return null or provide specific client exception (Subclass our exception)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my other comment: #2 (comment)
if (queueItem.isCancelled()) { | ||
LOG.debug("Queue item is cancelled. Returning -1"); | ||
return -1; | ||
} else if (queueItem.isStuck()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably would require us to return some exception to the client - job needs to be retrgered. I do not remember where item can be stuck, but it this is permanent we should let clients now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wtrocki good point. This is a combined answer for the comment above #2 (comment) and this comment.
I don't like subclassing the client exception. That would mean some casting and instanceof calls.
Lets use this model then:
class BuildStatus{
STATE state;
int buildNumber;
}
enum STATE{
BUILDING,
QUEUE_ITEM_CANCELLED,
QUEUE_ITEM_STUCK,
TIMED_OUT
...
}
class DiggerClient{
...
public BuildStatus build(String jobName, long timeout) throws DiggerClientException{...}
}
Method will only throw exception in case of
- thread interruption during sleep calls
- connection problem with Jenkins
@@ -1,24 +1,23 @@ | |||
package com.redhat.digkins.services; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use org.aerogear.***
as package for all of this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's do the package change in a SEPARATE PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
unit tests ? |
@aliok Would be good to paste your example into README.md (create job is already there) |
Could not review change because of missing artifact: I needed to build it locally. |
PR extended in aliok#1 |
|
@wtrocki @matzew @josemigallas updates:
notes:
follow ups that I am gonna do immediately
How to test:
Note that you need to build Jenkins-Java-client and install it locally as described in previous comments. |
private final static String GIT_REPO_BRANCH = "GIT_REPO_BRANCH"; | ||
|
||
private final static String GIT_REPO_URL = "GIT_REPO_URL", GIT_REPO_BRANCH = "GIT_REPO_BRANCH"; | ||
private JenkinsServer jenkins; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be final
as in DiggerClient?
* @param gitBranch git repository branch (default branch used to checkout source code) | ||
*/ | ||
public void create(String name, String gitRepo, String gitBranch) throws IOException { | ||
JtwigTemplate template = JtwigTemplate.classpathTemplate("templates/job.xml"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly recommend to extract hardcoded strings into a constant field, this way it can be found, checked and modified easier when needed.
/** | ||
* How long should we wait before we start checking the queue item status. | ||
*/ | ||
public static final long FIRST_CHECK_DELAY = 5 * 1000L; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion: the time unit should be always explicit. In this case I believe they are millis so I would either name it FIRST_CHECK_DELAY_MILLIS
or include it in comment /** [...] to queue item status, in milli seconds. */
public static final long POLL_PERIOD = 2 * 1000L; | ||
|
||
|
||
private JenkinsServer jenkins; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be final
?
Merged this one. @josemigallas your concerns are done in a separate PR |
Reviewed. Looks ok.
DiggerClient should not have any logic and just pass all execution parameters to services so I would not bother too much |
@wtrocki on a second thought... you're right. I won't write tests for |
public long build(String jobName, long timeout)
inDiggerClient
Checked in as 2 separate commits: 1 for styling/formatting. 1 for the actual work.