Skip to content
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

Merged
merged 12 commits into from
Feb 7, 2018

Conversation

zackliu
Copy link
Contributor

@zackliu zackliu commented Dec 5, 2017

  • 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.

image
image

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")) {
Copy link

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?

Copy link
Contributor Author

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.

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

@jpricket
Copy link
Contributor

@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.

@zackliu
Copy link
Contributor Author

zackliu commented Jan 23, 2018

@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.

@jpricket
Copy link
Contributor

@zackliu I am not familiar with the Release code. @kasubram - Could you please provide all the types of release status?

this.isArchiveLog = isArchiveLog;
}

private Object readResolve() {

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)

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"));

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)

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?

Copy link
Contributor Author

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.

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);

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.

Copy link

@kasubram kasubram left a 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)) {

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.

Copy link
Contributor Author

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.

@zackliu
Copy link
Contributor Author

zackliu commented Jan 30, 2018

@kasubram CI build failed because it said File does not end with a newline in RemoteChangesetVersionCommand.java and TfsUserLookup.java. But actually I didn't change these two files and I found there is one new line at the end of these files.
The Checkstyle passed in my local build, and I noticed a lot of build failed in CI because of this issue. So, any solutions?


if (!SystemCredentialsProvider.getInstance().getDomainCredentialsMap().containsKey(requirement)) {
generateDomain(hostName);
}

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) {

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";

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");

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.

Copy link
Contributor Author

@zackliu zackliu Jan 31, 2018

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please log exception

@zackliu
Copy link
Contributor Author

zackliu commented Feb 1, 2018

@kasubram As we discussed, I removed archiving logs and add a link to VSTS logs page.
I updated the summary and screenshots, thus you can have a brief understanding.


private static final long serialVersionUID = -760016860995557L;

private static final long RELEASE_TIMEOUT_MINUTES = 120;
Copy link

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
Copy link

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";
Copy link

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'?>
Copy link

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;
Copy link

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 {
Copy link

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);
Copy link

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.
Copy link

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) {
Copy link

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) {

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please log

Copy link

@kasubram kasubram left a 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..

@zackliu
Copy link
Contributor Author

zackliu commented Feb 7, 2018

@kasubram Seems the PR has passed the CI. Could we merge it?

try {
SystemCredentialsProvider.getInstance().save();
} catch (IOException ignore) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a warning log?

@jpricket jpricket merged commit cdda7a0 into jenkinsci:master Feb 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants