Search code examples
azure-devopsazure-pipelines-release-pipeline

Replace Token task in the Release pipeline does not replace token in file


I'm new to this of Azure DevOps release. I'm trying to receive an artifact that contains a zip file that inside there is a config.json file that contains a simple variable inside.

{"apiUrl": "#{apiURL}#"}

This will be deployed in a server as an IIS application.I have already been able to publish the application in the IIS of the server. Now the problem is that this variable need to be changed to reflect the new path of an api that is in the server.

I am trying the following:

I created the variables for group, as well in the pipeline. Pipeline variable

Group Variable

First I extract the files File extraction

Then I replace token using the Replace tokens task: Replace token

Then I rezip the files to the correspondent place: Rezip files

Then deploy to the server: Server deploy

When the release runs it shows me the log of the replace as it did the change. Release replace

But the server still shows me the incorrect file. Server image

I have tried deleting the zip file, moving around the order of the tasks, tried to replace directly on the server (I fail miserably). If any have an idea what I'm missing. Please help.


Solution

  • I have checked the release pipeline task definition.

    The cause of the issue is that the archive file task will zip the files include the folder name.

    The following is the file structure in your zip package:

    -- 876 #$(build.buildid) foldername
      -- otherfiles
      -- config.json
    

    In this case, when you deploy the zip package to IIS Server, the config.json file(The apiUrl value updated) will show under the 876 folder instead of the root folder. It will not update the config.json file in the root folder

    From your screenshot, you are checking the config.json file in the root folder of the website. Therefore, the value of the variable does not change.

    You can check if there is a folder name: 876 and check if the config.json file value is correct in the folder 876.

    To solve the issue(change the config.json in the root folder), you need to disable the option: Prepend root folder name to archive paths in Archive files task.

    For Example:

    enter image description here

    It will exclude the root folder name and the file structure as below:

    -- otherfiles
    -- config.json
    

    In this case, it will update the config.json file in the root folder of the website.

    For more detailed info, you can refer to this doc: ArchiveFiles@2 - Archive files v2 task