mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
Fix the issue that script identity is not set when running a job
This commit is contained in:
parent
0c9d581499
commit
e89fc8f6e9
@ -314,7 +314,6 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
}
|
||||
|
||||
private JobExecution execute(Build build) {
|
||||
ScriptIdentity.push(new JobIdentity(build.getProject(), build.getCommitId()));
|
||||
Build.push(build);
|
||||
try {
|
||||
String jobToken = UUID.randomUUID().toString();
|
||||
@ -544,7 +543,6 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
}
|
||||
} finally {
|
||||
Build.pop();
|
||||
ScriptIdentity.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@ -842,7 +840,6 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
@Override
|
||||
public void run() {
|
||||
Build build = OneDev.getInstance(BuildManager.class).load(buildId);
|
||||
ScriptIdentity.push(new JobIdentity(build.getProject(), build.getCommitId()));
|
||||
Build.push(build);
|
||||
try {
|
||||
Job job = (Job) VariableInterpolator.installInterceptor(build.getJob());
|
||||
@ -856,7 +853,6 @@ public class DefaultJobManager implements JobManager, Runnable, CodePullAuthoriz
|
||||
logger.error(message, e);
|
||||
} finally {
|
||||
Build.pop();
|
||||
ScriptIdentity.pop();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -70,6 +70,8 @@ import io.onedev.server.util.facade.BuildFacade;
|
||||
import io.onedev.server.util.inputspec.SecretInput;
|
||||
import io.onedev.server.util.interpolative.Interpolative;
|
||||
import io.onedev.server.util.patternset.PatternSet;
|
||||
import io.onedev.server.util.script.identity.JobIdentity;
|
||||
import io.onedev.server.util.script.identity.ScriptIdentity;
|
||||
import io.onedev.server.web.editable.BeanDescriptor;
|
||||
import io.onedev.server.web.editable.PropertyDescriptor;
|
||||
import io.onedev.server.web.editable.annotation.Editable;
|
||||
@ -781,9 +783,11 @@ public class Build extends AbstractEntity implements Referenceable {
|
||||
|
||||
public static void push(Build build) {
|
||||
stack.get().push(build);
|
||||
ScriptIdentity.push(new JobIdentity(build.getProject(), build.getCommitId()));
|
||||
}
|
||||
|
||||
public static void pop() {
|
||||
ScriptIdentity.pop();
|
||||
stack.get().pop();
|
||||
}
|
||||
|
||||
|
||||
@ -74,17 +74,20 @@ public class GroovyUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new OneException("No authorized groovy script found: "
|
||||
+ GroovyScript.BUILTIN_PREFIX + scriptName);
|
||||
} else {
|
||||
for (GroovyScript script: OneDev.getInstance(SettingManager.class).getGroovyScripts()) {
|
||||
if (script.getName().equals(scriptName) && script.isAuthorized(ScriptIdentity.get())) {
|
||||
try {
|
||||
return evalScript(StringUtils.join(script.getContent(), "\n"), variables);
|
||||
} catch (Exception e) {
|
||||
throw new OneException("Error evaluating named groovy script: " + scriptName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new OneException("No authorized groovy script found: " + scriptName);
|
||||
}
|
||||
for (GroovyScript script: OneDev.getInstance(SettingManager.class).getGroovyScripts()) {
|
||||
if (script.getName().equals(scriptName) && script.isAuthorized(ScriptIdentity.get())) {
|
||||
try {
|
||||
return evalScript(StringUtils.join(script.getContent(), "\n"), variables);
|
||||
} catch (Exception e) {
|
||||
throw new OneException("Error evaluating named groovy script: " + scriptName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new OneException("No authorized groovy script found: " + scriptName);
|
||||
}
|
||||
|
||||
public static Object evalScript(String scriptContent, Map<String, Object> variables) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user