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

Allow TokenMacro in Stash server URL Fixes [JENKINS-31117] #153

Merged
merged 3 commits into from May 2, 2017

Conversation

mdkf
Copy link
Contributor

@mdkf mdkf commented Apr 13, 2017

Fixes https://issues.jenkins-ci.org/browse/JENKINS-31117 aka #139
Uses latest Parent POM
Fixes some FindBugs warnings

@scaytrase
Copy link
Member

The diff looks weird. Could you please rebase your changes on the latest release/1.x branch?

@mdkf
Copy link
Contributor Author

mdkf commented Apr 13, 2017

@scaytrase Sorry about that. I fixed the history.

Copy link
Member

@scaytrase scaytrase left a comment

Choose a reason for hiding this comment

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

Generally looks ok, small fixes requested. I'll test is as soon as I can

private String expandStashURL(Run<?, ?> run, final TaskListener listener) {
String url = stashServerBaseUrl;
DescriptorImpl descriptor = getDescriptor();
if ("".equals(url) || url == null) {
Copy link
Member

Choose a reason for hiding this comment

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

should this be (url == null || url.isEmpty() ) as same as above changes?

if ("".equals(url) || url == null)
url = descriptor.getStashRootUrl();

final Item project,
Copy link
Member

Choose a reason for hiding this comment

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

indentation

PrintStream logger = listener.getLogger();
logger.println("Unable to expand Stash Server URL");
ex.printStackTrace(logger);
}
Copy link
Member

Choose a reason for hiding this comment

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

indentation

@mdkf
Copy link
Contributor Author

mdkf commented Apr 13, 2017

@scaytrase . I reformatted the file as requested. It still looks a bit off in the diff, but looks ok in NetBeans.

@scaytrase
Copy link
Member

Unfortunatelly I cannot make it working. I've tried the following example

    withEnv(["STASH_URL=https://my.local.server"]) {
        sh "echo $STASH_URL"
        step([$class: 'StashNotifier', projectKey:"test", stashServerBaseUrl:'$STASH_URL'])         // Notifies the Stash Instance of the build result
    } 

also tried ${env.STASH_URL}, no luck. Gives me the following exception stacktrace:

Checking out Revision e52bee5f6d7cac82e5897964fa69b0d705f99514 (refs/remotes/origin/master)
[Pipeline] withEnv
[Pipeline] {
[Pipeline] sh
[stashnotifier-test] Running shell script
+ echo https://my.local.server
https://my.local.server
[Pipeline] step
Unable to expand Stash Server URL
org.jenkinsci.plugins.tokenmacro.MacroEvaluationException: Unrecognized macro 'STASH_URL' in '${STASH_URL}'
	at org.jenkinsci.plugins.tokenmacro.Parser.processToken(Parser.java:326)
	at org.jenkinsci.plugins.tokenmacro.Action$KiHW1UeqOdqAwZul.run(Unknown Source)
	at org.parboiled.matchers.ActionMatcher.match(ActionMatcher.java:96)
	at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77)
	at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)
	at org.parboiled.matchers.SequenceMatcher.match(SequenceMatcher.java:46)
	at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77)
	at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)
	at org.parboiled.matchers.FirstOfMatcher.match(FirstOfMatcher.java:41)
	at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77)
	at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)
	at org.parboiled.matchers.FirstOfMatcher.match(FirstOfMatcher.java:41)
	at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77)
	at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)
	at org.parboiled.matchers.ZeroOrMoreMatcher.match(ZeroOrMoreMatcher.java:39)
	at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77)
	at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)
	at org.parboiled.matchers.SequenceMatcher.match(SequenceMatcher.java:46)
	at org.parboiled.parserunners.BasicParseRunner.match(BasicParseRunner.java:77)
	at org.parboiled.MatcherContext.runMatcher(MatcherContext.java:351)
	at org.parboiled.parserunners.BasicParseRunner.run(BasicParseRunner.java:72)
	at org.parboiled.parserunners.ReportingParseRunner.runBasicMatch(ReportingParseRunner.java:86)
	at org.parboiled.parserunners.ReportingParseRunner.run(ReportingParseRunner.java:66)
	at org.parboiled.parserunners.AbstractParseRunner.run(AbstractParseRunner.java:81)
	at org.parboiled.parserunners.AbstractParseRunner.run(AbstractParseRunner.java:76)
	at org.jenkinsci.plugins.tokenmacro.Parser.process(Parser.java:68)
	at org.jenkinsci.plugins.tokenmacro.TokenMacro.expand(TokenMacro.java:204)
	at org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(TokenMacro.java:234)
	at org.jenkinsci.plugins.tokenmacro.TokenMacro.expandAll(TokenMacro.java:212)
	at org.jenkinsci.plugins.stashNotifier.StashNotifier.expandStashURL(StashNotifier.java:828)
	at org.jenkinsci.plugins.stashNotifier.StashNotifier.notifyStash(StashNotifier.java:692)
	at org.jenkinsci.plugins.stashNotifier.StashNotifier.processJenkinsEvent(StashNotifier.java:289)
	at org.jenkinsci.plugins.stashNotifier.StashNotifier.perform(StashNotifier.java:242)
	at org.jenkinsci.plugins.stashNotifier.StashNotifier.perform(StashNotifier.java:216)
	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:78)
	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:65)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:49)
	at hudson.security.ACL.impersonate(ACL.java:260)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:46)
	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)
Notifying Stash at "$env.STASH_URL"

Can you provide me an example, how can I put the URL into pipeline to make it being expanded as token?

@scaytrase
Copy link
Member

Non-pipeline job is failing expanding token too. Configuring it with Inject environment variables to the build process section and invoking as $STASH_URL`${STASH_URL}`.

@mdkf
Copy link
Contributor Author

mdkf commented May 1, 2017

Hi @scaytrase I'm running it right now on my production server with the following config and it works:
image
image

@mdkf
Copy link
Contributor Author

mdkf commented May 1, 2017

@scaytrase Only variables created in the Pre-Build and Post-Build are available to a post-build process. That is a limitation of Jenkins. If your test case created the variable during the build it will be lost when the post build process executes. That is why in my example the SHA1 is saved to a properties file. The injected variable was no longer accessible.

@scaytrase
Copy link
Member

@mdkf managed to get it working with classic builds and evaluated groovy script of envinject plugin (generic script didn't work)

But cannot get a pipeline working with it. Can you help me with a sample?

@mdkf
Copy link
Contributor Author

mdkf commented May 2, 2017

Hi @scaytrase . I have never used pipeline. From the docs, it seems there are some known issues with EnvInject and pipelines: https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin#EnvInjectPlugin-JenkinsPipeline

@scaytrase
Copy link
Member

@mdkf thanks for investigation, I think I've to merge it as is, since everything else works OK

Thank you!

@scaytrase scaytrase merged commit f4eca91 into jenkinsci:release/1.x May 2, 2017
@mdkf
Copy link
Contributor Author

mdkf commented May 2, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants