-
Notifications
You must be signed in to change notification settings - Fork 171
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
Release configuration and archiving VSTS logs improvement #189
Conversation
zackliu
commented
Dec 5, 2017
•
edited
Loading
edited
- Support using credentials Id and dropdown list to choose Team project and Release definition.
- Auto generate credentials (if cannot using the existing one) for backwards compatibility.
- Add a release logs link in build page.
listener.getLogger().printf("Waiting for release to be finished...%n"); | ||
while (true) { | ||
String status = releaseManagementHttpClient.GetReleaseStatus(this.projectName, object.getString("id")); | ||
if (status.equals("finished")) { |
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.
what if someone cancelled the release or deleted it. This will forever check the status. We should handle other status as well.
Also, what if there is a post approval which has not been approved for days. This will continue to check for that many days. We should also have a timeout to stop checking.
For one of the above reason if the release is not succeeded and we stopped checking for status and no logs uploaded to jenkins workspace, in that case whenever the jenkins build page is opened we can check once again to see the current status of that release and update the jenkins workspace. is this achievable?
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 will check more status and add a time watcher. Do you know where to get documents about the all types of status. I can't find it.
For the last suggestion, I think it's hard to achieve. Because the environment may be changed a lot after build. The workspace may no longer exists after build (User may use dynamic slave and once the build is over, the slave will be deleted) or the configuration has changed. So deal with the old builds may cause unexpected issues. Thus, I think it's make sense to skip the unachievable logs.
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.
It is there in Microsoft.VisualStudio.Services.ReleaseManagement.WebApi.EnvironmentStatus
Possible status are,
Undefined, NotStarted, InProgress, Succeeded, Canceled, Rejected, Queued, Scheduled, PartiallySucceeded
@zackliu - The changes to the TfsConfiguration class seem fine, but the last commit is failing to build. The errors appear to be related to CheckStyle. Please correct the build errors so that we can merge this successfully. |
@jpricketMSFT Could you please provide all the types of release status, I can't find it in docs. Thus I can fix the bug kasubram commented before. |
this.isArchiveLog = isArchiveLog; | ||
} | ||
|
||
private Object readResolve() { |
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.
shouldn't this be protected?
|
||
private Object readResolve() { | ||
if (StringUtils.isNotBlank(collectionUrl) | ||
&& StringUtils.isNotBlank(username) |
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.
also if its VSTS and we are using PAT, the username will be empty.
if (StringUtils.isNotBlank(this.destinationPath)) { | ||
listener.getLogger().printf("Waiting for release to be finished...%n"); | ||
while (true) { | ||
String status = releaseManagementHttpClient.GetReleaseStatus(this.projectName, object.getString("id")); |
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.
change it to IsReleaseSucceded? and return a bool?
{ | ||
throw new ReleaseManagementException(ex); | ||
} | ||
catch(IOException ex) |
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.
we are already dealing with the generic Exception. Do we need to catch the HttpException and IOException separately?
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 don't think it's useful to catch different types of exceptions but throw the same type in the end. However, I just follow the previous functions like ExecuteGetMethod
or ExecutePostmethod
. So, do we need to also change these functions to just catch generic 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.
I am not sure how we ended up having that code to catch different exception but finally throw the same exception. Please fix your method just to handle generic exception. Get and Post method I will fix it later.
{ | ||
String url = this.accountUrl + "/_apis/projects?api-version=1.0"; | ||
String response = this.ExecuteGetMethod(url); | ||
TeamProject teamProject = new Gson().fromJson(response, TeamProject.class); |
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 do something like,
values = new JSONObject(response).getString("value");
List projects = new Gson().fromJson(values, TeamProject[].class);
The teamproject object is not really representing the teamproject. The api returns a list of teamproject and a count. Looks like we want an intermediate object to represent that, but the final outcome we are looking is List. Looks like just parsing the value field is good enough.
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.
Sorry for the delay, have left few more comments, please take a look and let me know. Did you test back compat scenario. (install the old plugin and create a post build action and update to new plugin version and see if everything works fine)
@@ -163,6 +241,36 @@ void CreateRelease( | |||
JSONObject object = new JSONObject(response); | |||
listener.getLogger().printf("Release Name: %s%n", object.getString("name")); | |||
listener.getLogger().printf("Release id: %s%n", object.getString("id")); | |||
|
|||
if (StringUtils.isNotBlank(this.destinationPath)) { |
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.
also can we wait for release completion only if isArchiveLog is set to true. with the current change it always waits for release completion whether we archive or not. If someone does not want to wait for release completion, he could uncheck isArchiveLog.
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.
In the current change, if user leave destination path
blank, we won't wait for release completion. Do you means that if user uncheck isArchiveLog
, whether he fills in destination path
or not, we won't download logs for he.
@kasubram CI build failed because it said |
|
||
if (!SystemCredentialsProvider.getInstance().getDomainCredentialsMap().containsKey(requirement)) { | ||
generateDomain(hostName); | ||
} |
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.
leave a space after the brace
for (ReleaseDefinition releaseDefinition : releaseDefinitions) { | ||
listBoxModel.add(releaseDefinition.getName()); | ||
} | ||
} catch (ReleaseManagementException ignore) { |
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.
please log
|
||
public void GetReleaseLogs(String project, String releaseId, BuildListener listener) throws ReleaseManagementException | ||
{ | ||
String url = this.accountUrl + project + "/_apis/release/releases/" + "2" + "/logs?api-version=4.0-preview.2"; |
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.
aren't you supposed to use the releaseId instead of hardcoding "2"?
InputStream inputStream = this.ExecuteGetMethodAsStream(url); | ||
|
||
try { | ||
FileOutputStream out = new FileOutputStream("/home/chenyl/tmp.zip"); |
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.
please remove this home path. You need use File.CreateTempFile.
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.
You're seeing codes of the first commit. It's already different in the latest commit.
IOUtils.copy(inputStream, out); | ||
out.close(); | ||
} catch (Exception 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.
Please log exception
@kasubram As we discussed, I removed archiving logs and add a link to VSTS logs page. |
|
||
private static final long serialVersionUID = -760016860995557L; | ||
|
||
private static final long RELEASE_TIMEOUT_MINUTES = 120; |
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.
please remove the unused variables
@@ -163,6 +233,9 @@ void CreateRelease( | |||
JSONObject object = new JSONObject(response); | |||
listener.getLogger().printf("Release Name: %s%n", object.getString("name")); | |||
listener.getLogger().printf("Release id: %s%n", object.getString("id")); | |||
String logLink = this.collectionUrl + this.projectName |
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 call it releaseUrl?
@@ -163,6 +233,9 @@ void CreateRelease( | |||
JSONObject object = new JSONObject(response); | |||
listener.getLogger().printf("Release Name: %s%n", object.getString("name")); | |||
listener.getLogger().printf("Release id: %s%n", object.getString("id")); | |||
String logLink = this.collectionUrl + this.projectName | |||
+ "/_release?releaseId=" + object.getString("id") + "&_a=release-logs"; |
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.
Please do not construct the url by hand. In the release object under _link property you will notice "self" and 'web" keys. Use the url under the "web" key.
@@ -0,0 +1,6 @@ | |||
<?jelly escape-by-default='true'?> |
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 call it release summary?
public class LogSummaryAction extends InvisibleAction { | ||
private String projectName; | ||
private int buildNo; | ||
private String logLink; |
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.
releaseLink?
*/ | ||
|
||
@ExportedBean | ||
public class LogSummaryAction extends InvisibleAction { |
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 call it ReleaseSummaryAction?
@@ -163,6 +232,8 @@ void CreateRelease( | |||
JSONObject object = new JSONObject(response); |
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.
are we not converting to ReleaseDetails? if so then ReleaseDetails is not used anymore. If its not used anymore please remove the ReleaseDetails type.
import org.kohsuke.stapler.export.ExportedBean; | ||
|
||
/** | ||
* Show release logs link in build page. |
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.
show release link..
for (Project project : projects) { | ||
listBoxModel.add(project.getName()); | ||
} | ||
} catch (ReleaseManagementException ignored) { |
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.
please log.. otherwise we will have tough time to debug..
this.credentialsId | ||
= TeamCollectionConfiguration.setCredentials(hostName, username, password.getPlainText()); | ||
} catch (Exception ignore) { | ||
|
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.
please log
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.
One concern I have is, we do not log the exception. It will be hard to debug. Please go ahead and add logs. Otherwise changes are looking good..
@kasubram Seems the PR has passed the CI. Could we merge it? |
try { | ||
SystemCredentialsProvider.getInstance().save(); | ||
} catch (IOException ignore) { | ||
|
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.
add a warning log?