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-42556] Make PlaceholderTask.getFullDisplayName ignore thread authentication #34

Merged

Conversation

Projects
None yet
4 participants
@jglick
Copy link
Member

commented Mar 9, 2017

return Run.fromExternalizableId(runId);
SecurityContext orig = ACL.impersonate(ACL.SYSTEM);
try {
return Run.fromExternalizableId(runId);

This comment has been minimized.

Copy link
@jglick

jglick Mar 9, 2017

Author Member

Not to worry about showing the task to other users in the executor widget; this display code already handled that, since run() will normally return something without an access check (while the node block is up and running)—this code path is only used during ExecutorPickle rehydration when resuming a build.

import org.jvnet.hudson.test.RestartableJenkinsRule;

public class ExecutorPickleTest {

@ClassRule public static BuildWatcher buildWatcher = new BuildWatcher();
@Rule public RestartableJenkinsRule r = new RestartableJenkinsRule();
//@Rule public LoggerRule logging = new LoggerRule().record(Queue.class, Level.FINE);

This comment has been minimized.

Copy link
@jglick

jglick Mar 9, 2017

Author Member

Useful with jenkinsci/jenkins#2791, and triggers further exceptions fixed in jenkinsci/jenkins#2792.

r.j.jenkins.setAuthorizationStrategy(new MockAuthorizationStrategy().
grant(Jenkins.ADMINISTER).everywhere().to("admin").
grant(Jenkins.READ, Item.DISCOVER).everywhere().toEveryone());
r.j.jenkins.save(); // TODO pending https://github.com/jenkinsci/jenkins/pull/2790

This comment has been minimized.

Copy link
@jglick
@Override public void evaluate() throws Throwable {
SemaphoreStep.success("wait/1", null);
WorkflowJob p = r.j.jenkins.getItemByFullName("p", WorkflowJob.class);
assertFalse(p.getACL().hasPermission(Jenkins.ANONYMOUS, Item.READ));

This comment has been minimized.

Copy link
@jglick

jglick Mar 9, 2017

Author Member

verifying that save worked

WorkflowJob p = r.j.createProject(WorkflowJob.class, "p");
p.setDefinition(new CpsFlowDefinition("node('remote') {semaphore 'wait'}", true));
SemaphoreStep.waitForStart("wait/1", p.scheduleBuild2(0).waitForStart());
remote.toComputer().setTemporarilyOffline(true, new OfflineCause.UserCause(User.get("admin"), "hold"));

This comment has been minimized.

Copy link
@jglick

jglick Mar 9, 2017

Author Member

Otherwise ExecutorPickle could resume too quickly without ever even trying to print a message about its progress.

WorkflowJob p = r.j.jenkins.getItemByFullName("p", WorkflowJob.class);
assertFalse(p.getACL().hasPermission(Jenkins.ANONYMOUS, Item.READ));
WorkflowRun b = p.getBuildByNumber(1);
r.j.waitForMessage(Messages.ExecutorPickle_waiting_to_resume(Messages.ExecutorStepExecution_PlaceholderTask_displayName(b.getFullDisplayName())), b);

This comment has been minimized.

@reviewbybees

This comment has been minimized.

Copy link

commented Mar 9, 2017

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@svanoort
Copy link
Member

left a comment

🐝 Looks okay to me -- don't 100% understand the test but the code itself is straightforward.

@abayer

abayer approved these changes Mar 9, 2017

@jglick

This comment has been minimized.

Copy link
Member Author

commented Mar 10, 2017

don't 100% understand the test

FTR, this is the build output before the patch:

Started
[Pipeline] node
Running on remote in …/workspace/p
[Pipeline] {
[Pipeline] semaphore
Resuming build at Thu Mar 09 19:30:34 EST 2017 after Jenkins restart
[Pipeline] End of Pipeline
java.io.IOException: Failed to load build state
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$3.onSuccess(CpsFlowExecution.java:586)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$3.onSuccess(CpsFlowExecution.java:584)
	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$4$1.run(CpsFlowExecution.java:627)
	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:35)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.acegisecurity.AccessDeniedException: Please login to access job p
	at jenkins.model.Jenkins.getItem(Jenkins.java:2398)
	at jenkins.model.Jenkins.getItem(Jenkins.java:306)
	at jenkins.model.Jenkins.getItemByFullName(Jenkins.java:2504)
	at hudson.model.Run.fromExternalizableId(Run.java:2282)
	at org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution$PlaceholderTask.runForDisplay(ExecutorStepExecution.java:384)
	at org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution$PlaceholderTask.getDisplayName(ExecutorStepExecution.java:397)
	at org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution$PlaceholderTask.getFullDisplayName(ExecutorStepExecution.java:406)
	at org.jenkinsci.plugins.workflow.support.pickles.ExecutorPickle$1.printWaitingMessage(ExecutorPickle.java:116)
	at org.jenkinsci.plugins.workflow.support.pickles.TryRepeatedly$1.run(TryRepeatedly.java:95)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	... 3 more
Finished: FAILURE

and after:

Started
[Pipeline] node
Running on remote in …/workspace/p
[Pipeline] {
[Pipeline] semaphore
Resuming build at Thu Mar 09 19:31:30 EST 2017 after Jenkins restart
Waiting to resume part of p #1: ???
Ready to run at Thu Mar 09 19:31:32 EST 2017
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

@jglick jglick merged commit 30c1394 into jenkinsci:master Mar 10, 2017

@jglick jglick deleted the jglick:TryRepeatedly-anonDiscover-JENKINS-42556 branch Mar 10, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.