[email-ext plugin] rooturl is always null

Hi all,

I’m currently sending an email after some robot tests to give everyone the test results.
In this email, I want to put a link to the runned job, so i can easily go to the concerned job.

I used this line :

<td><A href="${rooturl}${build.url}">${rooturl}${build.url}</A></td>

but I always got something like:
nulljob/cp-robotframework-tests/job/controller/3044/

I have properly set up my Jenkins url in administration :
image

yet it is always a null value.

Does anyone has an idea why ? Am I missing some configuration ?

Here is my Jenkins setup:

Jenkins: 2.414.3
OS: Windows 10 - 10.0
Java: 11.0.4 - AdoptOpenJDK (OpenJDK 64-Bit Server VM)

Parameterized-Remote-Trigger:3.1.6.3
ace-editor:1.1
active-directory:2.34
ant:475.vf34069fef73c
antisamy-markup-formatter:159.v25b_c67cd35fb_
apache-httpcomponents-client-4-api:4.5.14-208.v438351942757
artifactory:4.0.0
authentication-tokens:1.4
badge:1.9.1
basic-branch-build-strategies:1.3.2
blueocean:1.25.6
blueocean-autofavorite:1.2.5
blueocean-bitbucket-pipeline:1.25.6
blueocean-commons:1.25.6
blueocean-config:1.25.6
blueocean-core-js:1.25.6
blueocean-dashboard:1.25.6
blueocean-display-url:2.4.1
blueocean-events:1.25.6
blueocean-git-pipeline:1.25.6
blueocean-github-pipeline:1.25.6
blueocean-i18n:1.25.6
blueocean-jira:1.25.6
blueocean-jwt:1.25.6
blueocean-personalization:1.25.6
blueocean-pipeline-api-impl:1.25.6
blueocean-pipeline-editor:1.25.6
blueocean-pipeline-scm-api:1.25.6
blueocean-rest:1.25.6
blueocean-rest-impl:1.25.6
blueocean-web:1.25.6
bootstrap4-api:4.6.0-5
bootstrap5-api:5.3.0-1
bouncycastle-api:2.28
branch-api:2.1071.v1a_188a_562481
build-timeout:1.21
caffeine-api:3.1.8-133.v17b_1ff2e0599
checks-api:2.0.0
cloudbees-bitbucket-branch-source:785.ve724eb_44e286
cloudbees-folder:6.858.v898218f3609d
command-launcher:100.v2f6722292ee8
commons-lang3-api:3.13.0-62.v7d18e55f51e2
commons-text-api:1.10.0-36.vc008c8fcda_7b_
config-file-provider:959.vcff671a_4518b_
copyartifact:1.47
credentials:1307.v3757c78f17c3
credentials-binding:642.v737c34dea_6c2
dependency-track:4.2.0
display-url-api:2.200.vb_9327d658781
docker-commons:1.19
docker-workflow:521.v1a_a_dd2073b_2e
durable-task:500.v8927d9fd99d8
echarts-api:5.4.0-5
email-ext:2.102
external-monitor-job:192.ve979ca_8b_3ccd
favorite:2.4.1
file-parameters:205.vf6ce13b_e5dee
font-awesome-api:6.4.0-1
git:5.2.0
git-client:4.5.0
git-server:1.11
github:1.37.3.1
github-api:1.316-451.v15738eef3414
github-branch-source:1677.v731f745ea_0cf
gitlab-api:5.1.0-84.v491924123a_f7
gitlab-branch-source:650.va_d1ce6d01959
gitlab-plugin:1.7.16
gradle:1.39.4
h2-api:1.4.199
handlebars:3.0.8
handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953
htmlpublisher:1.31
instance-identity:173.va_37c494ec4e5
ionicons-api:56.v1b_1c8c49374e
ivy:2.2
jackson2-api:2.15.3-372.v309620682326
jakarta-activation-api:2.0.1-3
jakarta-mail-api:2.0.1-3
javadoc:226.v71211feb_e7e9
javax-activation-api:1.2.0-6
javax-mail-api:1.6.2-9
jaxb:2.3.9-1
jdk-tool:66.vd8fa_64ee91b_d
jenkins-design-language:1.25.6
jersey2-api:2.41-133.va_03323b_a_1396
jira:3.7.1
jjwt-api:0.11.5-77.v646c772fddb_0
job-dsl:1.81
jquery-detached:1.2.1
jquery3-api:3.7.0-1
jsch:0.1.55.61.va_e9ee26616e7
junit:1240.vf9529b_881428
ldap:711.vb_d1a_491714dc
lockable-resources:2.16
mailer:463.vedf8358e006b_
matrix-auth:3.1.8
matrix-project:818.v7eb_e657db_924
maven-plugin:3.22
mercurial:2.16.2
mina-sshd-api-common:2.11.0-86.v836f585d47fa_
mina-sshd-api-core:2.11.0-86.v836f585d47fa_
momentjs:1.1.1
okhttp-api:4.11.0-157.v6852a_a_fa_ec11
p4:1.13.0
pam-auth:1.10
pipeline-build-step:516.v8ee60a_81c5b_9
pipeline-github-lib:38.v445716ea_edda_
pipeline-graph-analysis:202.va_d268e64deb_3
pipeline-groovy-lib:629.vb_5627b_ee2104
pipeline-input-step:477.v339683a_8d55e
pipeline-milestone-step:101.vd572fef9d926
pipeline-model-api:2.2114.v2654ca_721309
pipeline-model-definition:2.2114.v2654ca_721309
pipeline-model-extensions:2.2114.v2654ca_721309
pipeline-rest-api:2.34
pipeline-stage-step:305.ve96d0205c1c6
pipeline-stage-tags-metadata:2.2114.v2654ca_721309
pipeline-stage-view:2.34
pipeline-utility-steps:2.16.0
plain-credentials:143.v1b_df8b_d3b_e48
plugin-util-api:3.3.0
popper-api:1.16.1-3
popper2-api:2.11.5-2
powershell:1.7
pubsub-light:1.16
resource-disposer:0.19
robot:3.2.0
run-condition:1.5
scm-api:676.v886669a_199a_a_
script-security:1275.v23895f409fb_d
snakeyaml-api:2.2-111.vc6598e30cc65
sonar:2.14
sse-gateway:1.25
ssh-credentials:308.ve4497b_ccd8f4
sshd:3.312.v1c601b_c83b_0e
structs:325.vcb_307d2a_2782
timestamper:1.18
token-macro:384.vf35b_f26814ec
trilead-api:2.84.v72119de229b_7
tuleap-api:2.5.0
tuleap-git-branch-source:3.2.5
variant:59.vf075fe829ccb
windows-slaves:1.8.1
workflow-aggregator:590.v6a_d052e5a_a_b_5
workflow-api:1283.v99c10937efcb_
workflow-basic-steps:991.v43d80fea_ff66
workflow-cps:3806.va_3a_6988277b_2
workflow-durable-task-step:1199.v02b_9244f8064
workflow-job:1360.vc6700e3136f5
workflow-multibranch:716.vc692a_e52371b_
workflow-scm-step:415.v434365564324
workflow-step-api:639.v6eca_cd8c04a_a_
workflow-support:865.v43e78cc44e0d
ws-cleanup:0.42

In case you use freestyle jobs then you might want to use ${BUILD_URL} instead of ${rooturl}${build.url}

In pipeline you should use ${currentBuild.absoluteUrl}

I’m using a multiple branch pipeline, not a freestyle job, so BUILD_URL doesn’t seem a good solution.

However I tried currentBuild.absoluteUrl, which gives me this error :
Also: org.jenkinsci.plugins.workflow.actions.ErrorAction$ErrorId: d21a4277-bcf8-44ad-a9b4-7b8becec0dc5 11:55:47 java.lang.IllegalStateException: Root URL isn’t configured yet. Cannot compute absolute URL. 11:55:47 at hudson.model.Item.getAbsoluteUrl(Item.java:204) 11:55:47 at hudson.model.AbstractItem.getAbsoluteUrl(AbstractItem.java:594) 11:55:47 at hudson.model.Run.getAbsoluteUrl(Run.java:1070) 11:55:47 at org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.getAbsoluteUrl(RunWrapper.java:378) 11:55:47 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 11:55:47 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 11:55:47 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 11:55:47 at java.base/java.lang.reflect.Method.invoke(Method.java:566) 11:55:47 at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98) 11:55:47 at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325) 11:55:47 at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1845) 11:55:47 at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3773) 11:55:47 at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:195) 11:55:47 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:469)

Yet my URL seems alright in the configuration…

BUILD_URL should also be available in pipeline jobs I just noticed.

But the stacktrace you get indicates that the Jenkins url is not properly set for some reason in the global config. You should check the jenkins logs if there is a message Invalid URL received: <url>, considered as null

I don’t have the error you’re talking about, but instead I have this:
Found invalid crumb. If you are calling this URL with a script, please use the API Token instead. More information: https://www.jenkins.io/redirect/crumb-cannot-be-used-for-script

Mar 15, 2024 1:14:04 PM WARNING hudson.security.csrf.CrumbFilter doFilter

Not really sure how it is linked, but I got it only when I use absoluteUrl

In the same time, I’m trying BUILD_URL once more

Finally BUILD_URL did the trick.
I just got to get it from env var at the beginning of my template using

import hudson.model.Build
def BUILD_URL = build.getEnvironment(TaskListener.NULL)["BUILD_URL"];

Thanks for your guidelines on where to look !

Or just env.BUILD_URL.