mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
chore: Use unique build workspace and network for resubmitted build
This commit is contained in:
parent
d8da5a0197
commit
f6b438e2df
@ -7306,4 +7306,15 @@ public class DataMigrator {
|
||||
}
|
||||
}
|
||||
|
||||
private void migrate186(File dataDir, Stack<Integer> versions) {
|
||||
for (File file : dataDir.listFiles()) {
|
||||
if (file.getName().startsWith("Builds.xml")) {
|
||||
var dom = VersionedXmlDoc.fromFile(file);
|
||||
for (Element element : dom.getRootElement().elements()) {
|
||||
element.addElement("submitSequence").setText("1");
|
||||
}
|
||||
dom.writeToFile(file, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -179,7 +179,7 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
private volatile IMap<String, String> jobServers;
|
||||
|
||||
private volatile IMap<String, Date> sequentialKeys;
|
||||
|
||||
|
||||
private volatile Map<String, List<JobSchedule>> branchSchedules;
|
||||
|
||||
private volatile String maintenanceTaskId;
|
||||
@ -535,6 +535,7 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
String projectGitDir = projectManager.getGitDir(build.getProject().getId()).getAbsolutePath();
|
||||
Long buildId = build.getId();
|
||||
Long buildNumber = build.getNumber();
|
||||
Long buildSequence = build.getSubmitSequence();
|
||||
String refName = build.getRefName();
|
||||
ObjectId commitId = ObjectId.fromString(build.getCommitHash());
|
||||
BuildSpec buildSpec = build.getSpec();
|
||||
@ -565,11 +566,12 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
JobAuthorizationContext.pop();
|
||||
}
|
||||
|
||||
JobContext jobContext = new JobContext(jobToken, jobExecutor, sequentialGroup,
|
||||
projectId, projectPath, projectGitDir, buildId, buildNumber, actions,
|
||||
refName, commitId, services, timeout);
|
||||
JobContext jobContext = new JobContext(jobToken, jobExecutor, projectId, projectPath,
|
||||
projectGitDir, buildId, buildNumber, buildSequence, actions, refName, commitId,
|
||||
services, timeout);
|
||||
|
||||
return executorService.submit(() -> {
|
||||
int retried = 0;
|
||||
while (true) {
|
||||
long beginTime = System.currentTimeMillis();
|
||||
if (sequentialKey != null) {
|
||||
@ -607,11 +609,13 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
throwable = t;
|
||||
}
|
||||
|
||||
if (!checkRetry(job, jobContext, jobLogger, throwable)) {
|
||||
if (!checkRetry(job, jobContext, jobLogger, throwable, retried)) {
|
||||
if (throwable != null)
|
||||
throw ExceptionUtils.unchecked(throwable);
|
||||
else
|
||||
return false;
|
||||
} else {
|
||||
retried++;
|
||||
}
|
||||
} finally {
|
||||
Collection<Thread> threads = serverStepThreads.remove(jobToken);
|
||||
@ -629,8 +633,8 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
});
|
||||
}
|
||||
|
||||
private boolean checkRetry(Job job, JobContext jobContext, TaskLogger jobLogger, @Nullable Throwable throwable) {
|
||||
int retried = jobContext.getRetried();
|
||||
private boolean checkRetry(Job job, JobContext jobContext, TaskLogger jobLogger,
|
||||
@Nullable Throwable throwable, int retried) {
|
||||
if (retried < job.getMaxRetries() && sessionManager.call(() -> {
|
||||
RetryCondition retryCondition = RetryCondition.parse(job, job.getRetryCondition());
|
||||
AtomicReference<String> errorMessage = new AtomicReference<>(null);
|
||||
@ -664,7 +668,6 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
listenerRegistry.post(new BuildRetrying(innerBuild));
|
||||
buildManager.update(innerBuild);
|
||||
});
|
||||
jobContext.setRetried(retried+1);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@ -799,6 +802,7 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
}
|
||||
|
||||
build.setStatus(Build.Status.WAITING);
|
||||
build.setSubmitSequence(build.getSubmitSequence()+1);
|
||||
build.setJobToken(UUID.randomUUID().toString());
|
||||
build.setFinishDate(null);
|
||||
build.setPendingDate(null);
|
||||
|
||||
@ -9,7 +9,6 @@ import io.onedev.server.model.Project;
|
||||
import io.onedev.server.model.support.administration.jobexecutor.JobExecutor;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@ -20,9 +19,7 @@ public class JobContext implements Serializable {
|
||||
private final String jobToken;
|
||||
|
||||
private final JobExecutor jobExecutor;
|
||||
|
||||
private final String sequentialGroup;
|
||||
|
||||
|
||||
private final Long projectId;
|
||||
|
||||
private final String projectPath;
|
||||
@ -32,6 +29,8 @@ public class JobContext implements Serializable {
|
||||
private final Long buildId;
|
||||
|
||||
private final Long buildNumber;
|
||||
|
||||
private final Long submitSequence;
|
||||
|
||||
private final List<Action> actions;
|
||||
|
||||
@ -42,21 +41,19 @@ public class JobContext implements Serializable {
|
||||
private final List<ServiceFacade> services;
|
||||
|
||||
private final long timeout;
|
||||
|
||||
private volatile int retried;
|
||||
|
||||
public JobContext(String jobToken, JobExecutor jobExecutor, @Nullable String sequentialGroup,
|
||||
Long projectId, String projectPath, String projectGitDir, Long buildId,
|
||||
Long buildNumber, List<Action> actions, String refName, ObjectId commitId,
|
||||
List<ServiceFacade> services, long timeout) {
|
||||
|
||||
public JobContext(String jobToken, JobExecutor jobExecutor, Long projectId, String projectPath,
|
||||
String projectGitDir, Long buildId, Long buildNumber, Long submitSequence,
|
||||
List<Action> actions, String refName, ObjectId commitId, List<ServiceFacade> services,
|
||||
long timeout) {
|
||||
this.jobToken = jobToken;
|
||||
this.jobExecutor = jobExecutor;
|
||||
this.sequentialGroup = sequentialGroup;
|
||||
this.projectId = projectId;
|
||||
this.projectPath = projectPath;
|
||||
this.projectGitDir = projectGitDir;
|
||||
this.buildId = buildId;
|
||||
this.buildNumber = buildNumber;
|
||||
this.submitSequence = submitSequence;
|
||||
this.actions = actions;
|
||||
this.refName = refName;
|
||||
this.commitId = commitId;
|
||||
@ -72,11 +69,6 @@ public class JobContext implements Serializable {
|
||||
return jobExecutor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getSequentialGroup() {
|
||||
return sequentialGroup;
|
||||
}
|
||||
|
||||
public Long getBuildId() {
|
||||
return buildId;
|
||||
}
|
||||
@ -113,18 +105,14 @@ public class JobContext implements Serializable {
|
||||
return buildNumber;
|
||||
}
|
||||
|
||||
public Long getSubmitSequence() {
|
||||
return submitSequence;
|
||||
}
|
||||
|
||||
public long getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public int getRetried() {
|
||||
return retried;
|
||||
}
|
||||
|
||||
public void setRetried(int retried) {
|
||||
this.retried = retried;
|
||||
}
|
||||
|
||||
public LeafFacade getStep(List<Integer> stepPosition) {
|
||||
return LeafFacade.of(actions, stepPosition);
|
||||
}
|
||||
|
||||
@ -348,6 +348,8 @@ public class Build extends ProjectBelonging
|
||||
private String uuid = UUID.randomUUID().toString();
|
||||
|
||||
private long number;
|
||||
|
||||
private long submitSequence = 1L;
|
||||
|
||||
@Column(nullable=false)
|
||||
private String commitHash;
|
||||
@ -537,6 +539,14 @@ public class Build extends ProjectBelonging
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public long getSubmitSequence() {
|
||||
return submitSequence;
|
||||
}
|
||||
|
||||
public void setSubmitSequence(long submitSequence) {
|
||||
this.submitSequence = submitSequence;
|
||||
}
|
||||
|
||||
public String getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@ -354,7 +354,7 @@ public class KubernetesExecutor extends JobExecutor implements RegistryLoginAwar
|
||||
private String getNamespace(@Nullable JobContext jobContext) {
|
||||
if (jobContext != null) {
|
||||
return getName() + "-" + jobContext.getProjectId() + "-"
|
||||
+ jobContext.getBuildNumber() + "-" + jobContext.getRetried();
|
||||
+ jobContext.getBuildNumber() + "-" + jobContext.getSubmitSequence();
|
||||
} else {
|
||||
return getName() + "-executor-test";
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ public class RemoteDockerExecutor extends ServerDockerExecutor {
|
||||
|
||||
DockerJobData jobData = new DockerJobData(jobToken, getName(), jobContext.getProjectPath(),
|
||||
jobContext.getProjectId(), jobContext.getRefName(), jobContext.getCommitId().name(),
|
||||
jobContext.getBuildNumber(), jobContext.getActions(), jobContext.getRetried(),
|
||||
jobContext.getBuildNumber(), jobContext.getSubmitSequence(), jobContext.getActions(),
|
||||
jobContext.getServices(), registryLogins, isMountDockerSock(), getDockerSockPath(),
|
||||
getDockerBuilder(), getCpuLimit(), getMemoryLimit(), getRunOptions(),
|
||||
getNetworkOptions(), isAlwaysPullImage());
|
||||
|
||||
@ -98,7 +98,7 @@ public class RemoteShellExecutor extends ServerShellExecutor {
|
||||
String jobToken = jobContext.getJobToken();
|
||||
ShellJobData jobData = new ShellJobData(jobToken, getName(), jobContext.getProjectPath(),
|
||||
jobContext.getProjectId(), jobContext.getRefName(), jobContext.getCommitId().name(),
|
||||
jobContext.getBuildNumber(), jobContext.getActions());
|
||||
jobContext.getBuildNumber(), jobContext.getSubmitSequence(), jobContext.getActions());
|
||||
|
||||
try {
|
||||
return call(agentSession, jobData, jobContext.getTimeout()*1000L);
|
||||
|
||||
@ -266,11 +266,11 @@ public class ServerDockerExecutor extends JobExecutor implements RegistryLoginAw
|
||||
checkApplicable();
|
||||
|
||||
hostBuildHome = new File(Bootstrap.getTempDir(),
|
||||
"onedev-build-" + jobContext.getProjectId() + "-" + jobContext.getBuildNumber());
|
||||
"onedev-build-" + jobContext.getProjectId() + "-" + jobContext.getBuildNumber() + "-" + jobContext.getSubmitSequence());
|
||||
FileUtils.createDir(hostBuildHome);
|
||||
try {
|
||||
String network = getName() + "-" + jobContext.getProjectId() + "-"
|
||||
+ jobContext.getBuildNumber() + "-" + jobContext.getRetried();
|
||||
+ jobContext.getBuildNumber() + "-" + jobContext.getSubmitSequence();
|
||||
|
||||
String localServer = getClusterManager().getLocalServerAddress();
|
||||
jobLogger.log(String.format("Executing job (executor: %s, server: %s, network: %s)...",
|
||||
|
||||
@ -98,7 +98,7 @@ public class ServerShellExecutor extends JobExecutor implements Testable<TestDat
|
||||
checkApplicable();
|
||||
|
||||
buildHome = new File(Bootstrap.getTempDir(),
|
||||
"onedev-build-" + jobContext.getProjectId() + "-" + jobContext.getBuildNumber());
|
||||
"onedev-build-" + jobContext.getProjectId() + "-" + jobContext.getBuildNumber() + "-" + jobContext.getSubmitSequence());
|
||||
FileUtils.createDir(buildHome);
|
||||
File workspaceDir = new File(buildHome, "workspace");
|
||||
try {
|
||||
@ -125,7 +125,6 @@ public class ServerShellExecutor extends JobExecutor implements Testable<TestDat
|
||||
getJobManager().reportJobWorkspace(jobContext, workspaceDir.getAbsolutePath());
|
||||
CompositeFacade entryFacade = new CompositeFacade(jobContext.getActions());
|
||||
|
||||
OsInfo osInfo = OneDev.getInstance(OsInfo.class);
|
||||
var successful = entryFacade.execute(new LeafHandler() {
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user