Azure / azure-acr-plugin

Jenkins Azure ACR plugin
MIT License
2 stars 10 forks source link

Pipeline variable not able to be used in tagname #38

Open ghost opened 5 years ago

ghost commented 5 years ago

Within my Jenkins pipeline I have defined a variable (build number) Within the task were I create the docker images nd push it to ACR using the ACR Quick Task plugin. I would like to use that variable as my tag

So my Image name with tag field, looks like image_name:$VARIABLE

But I get this error:

ERROR: Failed to queue an ACR Quick Task: Some of the properties of 'runRequest' are invalid. InnerErrors: DockerBuildRequest:Image name 'image_name:$VARIABLE' is invalid. \nThe acceptable patterns are 'repository' or 'repository:tag'.The repository and tag names follow the standardized docker repository and tag naming conventions. Tag templates are supported within '{' and '}'. ERROR: ACR Quick Task ended with HasError Finished: FAILURE

To check if my variable is set, I created the build step "execute shell" and echo the $VARIABLE and there I get a number:

[task-name] $ /bin/sh -xe /tmp/jenkins6236765085731703135.sh
+ VARIABLE=12

To use the latest tag is not an option

gavinfish commented 5 years ago

@yuwzho Could you please take a look at this?

OmpahDev commented 5 years ago

Also having this problem.

yuwzho commented 5 years ago

Hi @sshorkey @FrankGNL We do nothing about the variable inside the plugin. Our as well many other Jenkins plugins' suggestion is to use the EnvInject Plugin to handle the varibale.

For instance, the imageNames can be written as imageNames: [[image: "<your image name>:$env.BUILD_NUMBER"]]

l3ender commented 3 years ago

I'm facing the same issue when trying to use a build variable in a Freestyle job:

image

This variable exists and is used elsewhere in the build, but errors when using this plugin:

ERROR: Failed to queue an ACR Quick Task: Some of the properties of 'runRequest' are invalid.. InnerErrors: DockerBuildRequest:Image name 'my-app:${DESIRED_TAG}' is invalid. The acceptable patterns are 'repository' or 'repository:tag'.The repository and tag names follow the standardized docker repository and tag naming conventions. Tag templates are supported within '{{' and '}}'.

I also tried without curly braces, like following. But the error still occurs.

my-app:$DESIRED_TAG

How can we make this input dynamic? Using latest is also not an option for me.

l3ender commented 3 years ago

There is a built-in Jenkins class which can handle environment variable expansion, so I've opened a PR with the fix: https://github.com/jenkinsci/azure-container-registry-tasks-plugin/pull/5.