jenkinsci / azure-artifact-manager-plugin

Jenkins Azure artifact manager plugin
https://plugins.jenkins.io/azure-artifact-manager/
MIT License
6 stars 10 forks source link

Using env var (eg ${JOB_NAME} ) in the "Azure Container Name" field (per the help) does not get replaced and results in exception #74

Closed aujasm1 closed 1 year ago

aujasm1 commented 1 year ago

Jenkins and plugins versions report

Environment ```text Paste the output here ```

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

Ubuntu 20.04

Reproduction steps

  1. Manage Jenkins > Configure System > Artifact Management for Builds > Add > Azure Artifact Storage > Azure Container Name = ${JOB_NAME} per the field description entry that says "Environment variables can also be referenced. For example: ${JOB_NAME}.
  2. When Jenkins Pipeline copyArtifacts clause runs it throws exception as follows, where it appears to have failed to replace the ENV var ref to JOB_NAME, a default Jenkins ENV var I thought available in all jobs:

java.net.URISyntaxException: Illegal character in path at index 54: https://epiphanybuildartifacts.blob.core.windows.net/${JOB_NAME} at java.base/java.net.URI$Parser.fail(URI.java:2913) at java.base/java.net.URI$Parser.checkChars(URI.java:3084) at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3166) at java.base/java.net.URI$Parser.parse(URI.java:3114) at java.base/java.net.URI.(URI.java:600) at java.base/java.net.URI.create(URI.java:881) Caused: java.lang.IllegalArgumentException: Illegal character in path at index 54: https://epiphanybuildartifacts.blob.core.windows.net/${JOB_NAME} at java.base/java.net.URI.create(URI.java:883) at com.azure.storage.blob.BlobContainerAsyncClient.(BlobContainerAsyncClient.java:147) at com.azure.storage.blob.BlobServiceAsyncClient.getBlobContainerAsyncClient(BlobServiceAsyncClient.java:163) at com.azure.storage.blob.BlobServiceClient.getBlobContainerClient(BlobServiceClient.java:77) at com.microsoft.jenkins.artifactmanager.Utils.getBlobContainerReference(Utils.java:139) at com.microsoft.jenkins.artifactmanager.AzureArtifactManager.archive(AzureArtifactManager.java:141) Caused: java.io.IOException at com.microsoft.jenkins.artifactmanager.AzureArtifactManager.archive(AzureArtifactManager.java:162) at hudson.tasks.ArtifactArchiver.perform(ArtifactArchiver.java:258) at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:101) at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:71) at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:829) Finished: FAILURE

Expected Results

I was expecting the plugin to write artifacts to a container in Azure Storage with a name equal to the name of the job in Jenkins.

Actual Results

I receive the exception noted above.

Anything else?

No response

aujasm1 commented 1 year ago

Forgot to mention that we're running: Jenkins 2.375.1 Azure Artifact Manager 115.vb0d5da76bb49

timja commented 1 year ago

The code for that is around here: https://github.com/jenkinsci/azure-artifact-manager-plugin/blob/65f5565c2e917ad0b868dd61721c7385e48b5477/src/main/java/com/microsoft/jenkins/artifactmanager/AzureArtifactManager.java#L87-L123

From a quick read it all seems supported and it definitely used to work but I haven't tried this in awhile.

aujasm1 commented 1 year ago

mmmm...ok....thank you Tim

I can see from the code that checkConfig calls Utils.containTokens(containerName).

containTokens then does a regex match using Constants.TOKEN_FORMAT:

    public static boolean containTokens(String text) {
        if (StringUtils.isBlank(text)) {
            return false;
        }
        return text.matches(**Constants.TOKEN_FORMAT**);
    }

Can you tell me where is this constant? I could not locate in Constants.java (alongside Utils.java). I'm wondering if this will give a clue to why its not detecting the ENV var properly?

aujasm1 commented 1 year ago

nvm, I think I found it at:

https://github.com/jenkinsci/azure-storage-plugin/blob/b575d77fa397e57dfe50eb8d7da7d10b6b480e03/src/main/java/com/microsoftopentechnologies/windowsazurestorage/helper/Constants.java#L44

public static final String TOKEN_FORMAT = "\\$([A-Za-z0-9_]+|\\{[A-Za-z0-9_]+\\})";

which seems ok......what part of the process does the ENV var lookup?

Is it another plugin that should be doing the replacement of the JOB_NAME var ref?