jenkinsci / badge-plugin

Jenkins Badge plugin
https://plugins.jenkins.io/badge/
MIT License
32 stars 43 forks source link

Width and height are not set for large icons (addBadge) #148

Closed Tersaramor closed 6 months ago

Tersaramor commented 6 months ago

Jenkins and plugins versions report

Jenkins: 2.440.3, Java 11.0.13, and plugins
OS: Linux - 5.4.0-90-generic
Java: 11.0.13 - Ubuntu (OpenJDK 64-Bit Server VM)
---
Parameterized-Remote-Trigger:3.2.0
allure-jenkins:3.29.0
allure-jenkins-plugin:2.31.1
ansicolor:1.0.4
antisamy-markup-formatter:162.v0e6ec0fcfcf6
apache-httpcomponents-client-4-api:4.5.14-208.v438351942757
apache-httpcomponents-client-5-api:5.3.1-1.0
asm-api:9.7-33.v4d23ef79fcc8
authentication-tokens:1.53.v1c90fd9191a_b_
badge:1.10
bootstrap5-api:5.3.3-1
bouncycastle-api:2.30.1.77-225.v26ea_c9455fd9
branch-api:2.1169.va_f810c56e895
build-name-setter:2.4.2
build-timeout:1.32
caffeine-api:3.1.8-133.v17b_1ff2e0599
checks-api:2.2.0
cloud-stats:336.v788e4055508b_
cloudbees-folder:6.901.vb_4c7a_da_75da_3
command-launcher:107.v773860566e2e
commons-lang3-api:3.13.0-62.v7d18e55f51e2
commons-text-api:1.11.0-109.vfe16c66636eb_
conditional-buildstep:1.4.3
config-file-provider:973.vb_a_80ecb_9a_4d0
credentials:1337.v60b_d7b_c7b_c9f
credentials-binding:677.vdc9d38cb_254d
display-url-api:2.204.vf6fddd8a_8b_e9
docker-commons:439.va_3cb_0a_6a_fb_29
docker-compose-build-step:1.0
docker-java-api:3.3.4-86.v39b_a_5ede342c
docker-plugin:1.6.1
docker-workflow:572.v950f58993843
durable-task:555.v6802fe0f0b_82
echarts-api:5.5.0-1
envinject:2.908.v66a_774b_31d93
envinject-api:1.199.v3ce31253ed13
extended-read-permission:53.v6499940139e5
font-awesome-api:6.5.2-1
generic-webhook-trigger:2.2.1
git:5.2.2
git-client:4.7.0
git-server:117.veb_68868fa_027
google-oauth-plugin:1.330.vf5e86021cb_ec
groovy-postbuild:228.vcdb_cf7265066
gson-api:2.10.1-15.v0d99f670e0a_7
instance-identity:185.v303dc7c645f9
ionicons-api:74.v93d5eb_813d5f
jackson2-api:2.17.0-379.v02de8ec9f64c
jakarta-activation-api:2.1.3-1
jakarta-mail-api:2.1.3-1
javadoc:243.vb_b_503b_b_45537
javax-activation-api:1.2.0-6
javax-mail-api:1.6.2-9
jaxb:2.3.9-1
jdk-tool:73.vddf737284550
jersey2-api:2.42-147.va_28a_44603b_d5
jjwt-api:0.11.5-112.ve82dfb_224b_a_d
jnr-posix-api:3.1.19-2
jobConfigHistory:1229.v3039470161a_d
joda-time-api:2.12.7-29.v5a_b_e3a_82269a_
jquery3-api:3.7.1-2
jsch:0.2.16-86.v42e010d9484b_
json-api:20240303-41.v94e11e6de726
json-path-api:2.9.0-58.v62e3e85b_a_655
junit:1265.v65b_14fa_f12f0
ldap:725.v3cb_b_711b_1a_ef
leastload:3.0.0
mailer:472.vf7c289a_4b_420
mapdb-api:1.0.9-40.v58107308b_7a_7
matrix-auth:3.2.2
matrix-project:822.824.v14451b_c0fd42
metrics:4.2.21-449.v6960d7c54c69
mina-sshd-api-common:2.12.1-101.v85b_e08b_780dd
mina-sshd-api-core:2.12.1-101.v85b_e08b_780dd
oauth-credentials:0.646.v02b_66dc03d2e
pam-auth:1.10
parameterized-scheduler:262.v00f3d90585cc
parameterized-trigger:806.vf6fff3e28c3e
pipeline-build-step:540.vb_e8849e1a_b_d8
pipeline-graph-analysis:216.vfd8b_ece330ca_
pipeline-groovy-lib:704.vc58b_8890a_384
pipeline-input-step:495.ve9c153f6067b_
pipeline-milestone-step:119.vdfdc43fc3b_9a_
pipeline-model-api:2.2198.v41dd8ef6dd56
pipeline-model-definition:2.2198.v41dd8ef6dd56
pipeline-model-extensions:2.2198.v41dd8ef6dd56
pipeline-rest-api:2.34
pipeline-stage-step:312.v8cd10304c27a_
pipeline-stage-tags-metadata:2.2198.v41dd8ef6dd56
pipeline-stage-view:2.34
pipeline-utility-steps:2.16.2
plain-credentials:179.vc5cb_98f6db_38
plugin-usage-plugin:4.4
plugin-util-api:4.1.0
rebuild:332.va_1ee476d8f6d
resource-disposer:0.23
role-strategy:727.vd344b_eec783d
run-condition:1.7
scm-api:690.vfc8b_54395023
script-security:1336.vf33a_a_9863911
sidebar-link:2.4.1
simple-theme-plugin:176.v39740c03a_a_f5
slack:715.v1cfed1b_9c63c
snakeyaml-api:2.2-111.vc6598e30cc65
ssh-agent:367.vf9076cd4ee21
ssh-credentials:337.v395d2403ccd4
ssh-slaves:2.948.vb_8050d697fec
sshd:3.322.v159e91f6a_550
structs:337.v1b_04ea_4df7c8
theme-manager:215.vc1ff18d67920
throttle-concurrents:2.14
timestamper:1.26
token-macro:400.v35420b_922dcb_
trilead-api:2.142.v748523a_76693
variant:60.v7290fc0eb_b_cd
workflow-aggregator:596.v8c21c963d92d
workflow-api:1291.v51fd2a_625da_7
workflow-basic-steps:1058.vcb_fc1e3a_21a_9
workflow-cps:3894.3896.vca_2c931e7935
workflow-durable-task-step:1336.v768003e07199
workflow-job:1400.v7fd111b_ec82f
workflow-multibranch:773.vc4fe1378f1d5
workflow-scm-step:427.v4ca_6512e7df1
workflow-step-api:657.v03b_e8115821b_
workflow-support:907.v6713a_ed8a_573

What Operating System are you using (both controller, and any agents involved in the problem)?

Ubuntu 20.04

Reproduction steps

  1. addBadge with large icon addBadge(icon: relativeIconPath, text: displayName, link: url)

Expected Results

Icon is 16x16

image

Actual Results

icon has actual size

image

Anything else?

Probably related to https://github.com/jenkinsci/badge-plugin/pull/130/files

image

Are you interested in contributing a fix?

No response

MarkEWaite commented 6 months ago

Thanks for the details. I can duplicate the problem with a one line Pipeline script using the set of plugins and versions you provided:

addBadge(icon: '/images/48x48/light-grey.gif', text: 'large icon')

Before

The icon is 16x16 even though the source icon is using a 48x48 icon. This is the preferred result.

screencapture-testing-b-markwaite-net-8080-job-badge-with-large-icon-2024-05-13-11_39_35-edit

After

The icon is 48x48. This is not the preferred result.

screencapture-testing-b-markwaite-net-8080-job-badge-with-large-icon-2024-05-13-11_41_54-edit

MarkEWaite commented 6 months ago

@Tersaramor I've attempted a fix for the bug. Could you confirm that the incremental build works well in your environment?

timonwalkley commented 6 months ago

It looks like we're still experiencing this issue on v1.12.

The larger images are coming from /images/svg...

addBadge(icon: "/images/svgs/logo.svg")

image

strangelookingnerd commented 6 months ago

Hey @timonwalkley. Sorry you still need to deal with this issue. I can reproduce it, however I think it has to do with the SVG itself as it does have some sort of sizing attached to it which I'm not sure we can actually override. I'll look a little deeper into it and come back to you as soon as possible.

strangelookingnerd commented 6 months ago

From what I can tell this happens for the "core" icons that can be referenced as either addBadge(icon: "/images/svgs/logo.svg") or addBadge(icon: "icon-logo") (the latter not being supported yet by this plugin).

It appears that in icon.jelly it is determined hey, this is a core icon using Functions and IconSet. There it is decided hey, since this is a core icon it has this size which is then used for the style.

This functionallity is rather complex and can likely not be adapted even though one could argue that overridding the actual given css class could be considered a bug.

Maybe someone from @jenkinsci/sig-ux could share some insights here or confirm my observations.

As of now it seems the only remedy is to hard-code the icon style="width: 16px; height: 16px;" in the plugin.

timja commented 6 months ago

can't you add something like the class icon-sm ?

strangelookingnerd commented 6 months ago

We already do that, but it does not seem to work for these icons - or at least not always. On my refactoring branch (#151) I can see that:

<span class="${it.cssClass}" style="${it.style}">
    <l:icon class="icon-sm" src="${it.icon}" alt="${it.text}" htmlTooltip="${it.text}"/>
</span>

does produce icons with width and height set to 48px when used with addBadge(icon: "/images/svgs/logo.svg") whereas:

<span class="${it.cssClass}" style="${it.style}">
    <l:icon class="icon-sm" style="width: 16px; height: 16px;" src="${it.icon}" alt="${it.text}" htmlTooltip="${it.text}"/>
</span>

works perfectly fine. Right now I fail to reproduce it on master (but I'm certain I did just an hour ago)

timja commented 6 months ago

I would be wary of defaulting to html for tooltips but that code looks fine

strangelookingnerd commented 6 months ago

Ok, now I get it - there is something fishy with how the path to the icon is determined in my local environment. Anyways:

<l:icon src="/images/svgs/logo.svg" class="icon-sm" />

results in the icon

grafik grafik

However

<l:icon src="/jenkins/static/40c46706/images/svgs/logo.svg" class="icon-sm" />

results in

grafik grafik

timja commented 6 months ago

The icon code is a mess, you would need to experiment with it to understand why this is happening: https://github.com/jenkinsci/jenkins/blob/master/core/src/main/resources/lib/layout/icon.jelly

I can't tell from just reading it.

strangelookingnerd commented 6 months ago

I tried to dig a little deeper into it and found that in IconSet#initializeSVGs all "core" svg are being added as icons for all the existing sizes. However in IconSet#addIcon they are added to the iconsByUrl map with their URL as key which is the same, no matter the size. Therefor the map contains those core icons only with the 48x48 / icon-xlg size. This map is used by icon.jelly via Functions#tryGetIcon

This means if i build an icon using /images/svgs/logo.svg I will always end up with the 48x48 variant. If i however use /jenkins/static/40c46706/images/svgs/logo.svg there is no entry for it in the map and I will therefor not use the icons style in icon.jelly

If I just use logo.svg I end up with the 24x24 variant because Functions#tryGetIcon will append the icon-md class.

I do agree this code is a mess and changing anything will end up causing more issues for sure. So the easiest remedy for me here is to hard-code the style or bypassing that issue with something like this.

timja commented 6 months ago

nice analysis. I'm sure it could be cleaned up, but would require some testing and analysis...

jonsgity commented 6 months ago

We are on Badge 1.12 and getting this sometimes when jobs are added to the queue: image

Is this the same issue? It goes away after several seconds and after refreshing the page. After that, the job appear in the queue as usual.

MarkEWaite commented 6 months ago

@jonsgity that does not seem like it is related to the badge plugin or at least it is a very different behavior than any other report. Please open a new issue and include the stack trace that has likely been written to the Jenkins log file when that message appears.

You can also test the build of this pull request in your environment to confirm that it does not resolve the issue. The "Checks" tab includes a section called "Incrementals". The page in that section provides a URL where you can download the build of this pull request.