microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.46k stars 2.6k forks source link

FileTransform correctly applies all transforms but still reports Error Unable to apply transformation for the given package - Changes are already present in the package. #13588

Closed Zhaph closed 3 years ago

Zhaph commented 3 years ago

Required Information

Question, Bug, or Feature?
Type: bug

Enter Task Name: FileTransform

Environment

Issue Description

I have a multi-stage YAML pipeline, that has the following Filesystem Transform task defined in a Deployment Job:

- task: FileTransform@2
  displayName: 'Apply Release Transforms'
  inputs:
    folderPath: '$(System.DefaultWorkingDirectory)\$(artifactName)\deploy\'
    enableXmlTransform: true
    xmlTransformationRules: |
      -transform *.Release.config -xml *.config
      -transform *.$(Environment.Name).config -xml *.config
      -transform config\**\*.Release.config -xml config\**\*.config
      -transform config\**\*.$(Environment.Name).config -xml config\**\*.config
    xmlTargetFiles: |
      web.config

We have two configuration files in the root of the application that need at least the Release transform applied (web.config and ApplicationInsights.config) as well as optional environment transforms. Similarly there are a number of .config files in the config folder, that have optional release and environment transforms.

Looking at the logs and the transformed files, all transforms are being correctly applied to the target files, but we are still getting the following error reported from the task (note that this is not stopping the deployment, but it is creating noise in the reports that makes it look like an error has occurred):

##[error]Unable to apply transformation for the given package - Changes are already present in the package.

Task logs

23.txt

Troubleshooting

Checkout how to troubleshoot failures and collect debug logs: https://docs.microsoft.com/en-us/vsts/build-release/actions/troubleshooting

Error logs

##[error]Unable to apply transformation for the given package - Changes are already present in the package.
AmrutaKawade commented 3 years ago

This is as per design https://github.com/microsoft/azure-pipelines-tasks/issues/12277

Zhaph commented 3 years ago

I would respectfully suggest then that the design is wrong.

There are no meaningful errors in the tasks, and they are successfully applying the transforms and replacements, but the tasks are erroneously reporting an error back to the pipeline and showing as errors on the report when in fact everything is behaving as expected.

How is this "by design"?

AmrutaKawade commented 3 years ago

There are some other requirements which made us to add this change. https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/FileTransformV2

The new File Transform Task version fails when no substitution has been applied (i.e. the changes were already present in the package).

If you don't want to fail task, you can check "Continue On Error" checkbox.

sharpjs commented 2 years ago

For anyone landing here who wants to squelch this error when doing JSON-only transforms:

xmlTransformationRules: ''
shemsiu commented 1 year ago

For anyone landing here who wants to squelch this error when doing JSON-only transforms:

xmlTransformationRules: ''

Just to follow up with an example:

- task: FileTransform@2
  inputs:
    folderPath: 'myFolder'
    jsonTargetFiles: 'appsettings.json'
    xmlTransformationRules: ''
alenroki commented 9 months ago

I can confirm that @shemsiu solution works. The error is not displayed when using xmlTransformationRules: ''

arialdomartini commented 4 months ago

If you don't want to fail task, you can check "Continue On Error" checkbox.

This is a terrible suggestion. I do want the pipeline to stop on errors.

That should not be an error in the first place. I would suggest fixing the root cause instead of suggesting us brittle workarounds.

farinha commented 1 month ago

I ran into this issue while using Classic Pipelines. It seems to me that this happens when there are no variable substitutions to be made.

I was in the process of creating a new stage and all existing variables were scoped specifically to other (existing) stages. As soon as I added a valid variable to the new stage's scope the problem went away.

It does seems useful to be notified when no transformations take place, as it highlights that some configuration might be missing. But for this to cause the task to trigger an error seems overkill and counterproductive. A warning seems like it would be more helpful.

crlmrlck commented 1 week ago

I would respectfully suggest then that the design is wrong.

There are no meaningful errors in the tasks, and they are successfully applying the transforms and replacements, but the tasks are erroneously reporting an error back to the pipeline and showing as errors on the report when in fact everything is behaving as expected.

How is this "by design"?

I feel like the error is misleading as well. It implies that transformations are happening twice, rather than transformations not happening. I spent wayyyyyyyyyyyyyyy too much time trying to find out why I was getting this error until I discovered this thread. Why in the world would I suspect XmlTransformationRule: "" would be the solve based on the error given.

This either needs to be set as an "Info" block, or the messaging needs to be updated to be more specific on what the issue really is.