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

[JENKINS-47803 && JENKINS-7009] Remove working copy if external is broken #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ THE SOFTWARE.
<version>2.0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.32.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
10 changes: 8 additions & 2 deletions src/main/java/hudson/scm/subversion/CheckoutUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.tmatesoft.svn.core.SVNCancelException;
import org.tmatesoft.svn.core.SVNDepth;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNErrorCode;
import org.tmatesoft.svn.core.internal.wc17.db.ISVNWCDb;
import org.tmatesoft.svn.core.internal.wc2.compat.SvnCodec;
import org.tmatesoft.svn.core.wc.SVNRevision;
Expand Down Expand Up @@ -137,8 +138,13 @@ public List<External> perform() throws IOException, InterruptedException {
throw (InterruptedException)new InterruptedException().initCause(e);
}
} catch (SVNException e) {
e.printStackTrace(listener.error("Failed to check out " + location.remote));
throw new IOException("Failed to check out " + location.remote, e) ;
if (e.getErrorMessage().getErrorCode() == SVNErrorCode.CL_ERROR_PROCESSING_EXTERNALS &&
!location.isCancelProcessOnExternalsFail()) {
// we should not fail if external failed
} else {
e.printStackTrace(listener.error("Failed to check out " + location.remote));
throw new IOException("Failed to check out " + location.remote, e);
}
} finally {
try {
pos.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.tmatesoft.svn.core.SVNCancelException;
import org.tmatesoft.svn.core.SVNErrorCode;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNErrorMessage;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.wc.ISVNExternalsHandler;
import org.tmatesoft.svn.core.wc.SVNEvent;
Expand Down Expand Up @@ -139,10 +140,10 @@ public void handleEvent(SVNEvent event, double progress) throws SVNException {
+ " failed!");
}

if (cancelProcessOnExternalsFailed) {
throw new SVNException(new RemotableSVNErrorMessage(SVNErrorCode.CL_ERROR_PROCESSING_EXTERNALS,
SVNErrorCode.CL_ERROR_PROCESSING_EXTERNALS.getDescription() + ": <" + file.getName() + ">"));
}
SVNErrorMessage error = new RemotableSVNErrorMessage(SVNErrorCode.CL_ERROR_PROCESSING_EXTERNALS,
SVNErrorCode.CL_ERROR_PROCESSING_EXTERNALS.getDescription() + ": <" + file.getName() + ">");

throw new SVNException(error, new SVNException(event.getErrorMessage()));
}

super.handleEvent(event, progress);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/scm/subversion/UpdateUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ public List<External> perform() throws IOException, InterruptedException {
} catch (final SVNException e) {
SVNException cause = e;
do {
if (location.isCancelProcessOnExternalsFail() &&
cause.getErrorMessage().getErrorCode() == SVNErrorCode.CL_ERROR_PROCESSING_EXTERNALS) {
break;
}

SVNErrorCode errorCode = cause.getErrorMessage().getErrorCode();
if (errorCode == SVNErrorCode.WC_LOCKED) {
// work space locked. try fresh check out
Expand Down
79 changes: 79 additions & 0 deletions src/test/java/hudson/scm/SubversionSCMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -1807,4 +1810,80 @@ private void invokeTestPollingExternalsForFile() throws Exception {
// should detect change
assertTrue(p.poll(StreamTaskListener.fromStdout()).hasChanges());
}

void lockWorkspace(String dbFile, String pathToLock) throws Exception {
Class.forName("org.sqlite.SQLiteJDBCLoader");
Connection conn = DriverManager.getConnection("jdbc:sqlite:" + dbFile);
PreparedStatement stmt = conn.prepareStatement("INSERT INTO WC_LOCK VALUES(1, ?, 1)");
stmt.setString(1, pathToLock);
stmt.executeUpdate();
conn.close();
}

@Issue("JENKINS-47803")
@Test
public void lockedExternal() throws Exception {
Proc p = runSvnServe(getClass().getResource("JENKINS-777.zip"));

try {
configureSvnWorkspaceFormat(SubversionWorkspaceSelector.WC_FORMAT_17);

FreeStyleProject b = r.createFreeStyleProject();

ModuleLocation[] locations = {
new ModuleLocation("svn://localhost/jenkins-777/proja", "proja", "infinity", false)
};

// do initial checkout
b.setScm(new SubversionSCM(Arrays.asList(locations), new UpdateUpdater(), null, null, null, null, null, null));
FreeStyleBuild build = r.assertBuildStatusSuccess(b.scheduleBuild2(0));

// Check that the external exists
FilePath ws = build.getWorkspace();
assertTrue(ws.child("proja").child("externals").child("projb").exists());

// mark external as locked
String db = ws.child("proja").child("externals").child("projb").child(".svn").child("wc.db").getRemote();
lockWorkspace(db, "externals");

// start second build and check if workspace is being reset (just check for the log)
build = r.assertBuildStatusSuccess(b.scheduleBuild2(0));
r.assertLogContains("Workspace appear to be locked, so getting a fresh workspace", build);
} finally {
p.kill();
}
}

@Test
public void ensureCancelOnExternalsFail() throws Exception {
Proc p = runSvnServe(getClass().getResource("JENKINS-777.zip"));

try {
configureSvnWorkspaceFormat(SubversionWorkspaceSelector.WC_FORMAT_17);

FreeStyleProject b = r.createFreeStyleProject();

ModuleLocation[] locations = {
new ModuleLocation("svn://localhost/jenkins-777/proja", null, "proja", "infinity", false, true)
};

// do initial checkout
b.setScm(new SubversionSCM(Arrays.asList(locations), new UpdateUpdater(), null, null, null, null, null, null));
FreeStyleBuild build = r.assertBuildStatusSuccess(b.scheduleBuild2(0));

// Check that the external exists
FilePath ws = build.getWorkspace();
assertTrue(ws.child("proja").child("externals").child("projb").exists());

// mark external as locked
String db = ws.child("proja").child("externals").child("projb").child(".svn").child("wc.db").getRemote();
lockWorkspace(db, "externals");

// start second build and check if build is canceled, caused by external failure
build = r.assertBuildStatus(Result.FAILURE, b.scheduleBuild2(0));
r.assertLogContains("Failed processing one or more externals definitions", build);
} finally {
p.kill();
}
}
}