2

I've created a pipeline and release in azure devops, but before i perform a swap of the slots i need to copy files from 'production' slot to my 'staging' slot. This is because our customer uploads file to the webapp itself (at least for now).

I've been doing some research and i dont think this is possible with a task in azure devops. I think its possible using powershell though.

Have anyone done this before?

sindrem
  • 1,211
  • 5
  • 24
  • 45

1 Answers1

1

This won't be possible out of the box. But you can do this over FTP. Here you have an example how to configure FTP access to you web app. And it would be the same for slot. So what you need is:

  • configure FTP access on your production slot
  • configure FTP access on your slot
  • copy files from production slot - here unfortunately there is no out of the box task to do this, so you need to use powershell like here
  • upload task to your slot using FTP Upload task

It would getting worse a bit if your slot is not long lived and you create it automatically. I'm not 100% sure, but it came to my mind that actually credential for you production slot may work also for other slots. So then you can skip second bullet and it should not be an issue with dynamically created slots.

Example powershell task: enter image description here

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • So i can run the powershell script in my release automatically? – sindrem Oct 26 '20 at 11:05
  • Yes of course. You can use powershell task on release pipeline. You can put script code as inline or download your source code and use file, or publish them from build pipeline as artifact and then download this artifact. – Krzysztof Madej Oct 26 '20 at 11:16
  • Do you have any idea what this means? I get the following error on this script: You cannot call a method on a null-valued expression. At C:\ftptest.ps1:18 char:9 + $reader.ReadLine() + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull – sindrem 3 mins ago Edit Delete – sindrem Oct 26 '20 at 14:55
  • Difficult to say without seeing script. However, do you use self hosted agents? Can you create a separate question to investigate this? – Krzysztof Madej Oct 26 '20 at 15:22
  • Commented on the other post. Thank you. – sindrem Oct 26 '20 at 16:50
  • @sindrem Since you have open a new case, can you [Accept this reply as an Answer](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) if it helps you solve current issue? This can be beneficial to other community members reading this thread. – Cece Dong - MSFT Oct 27 '20 at 02:31
  • Im not sure id it does yet, but if it works, it will – sindrem Oct 27 '20 at 06:21
  • Hello. I have been able to execute WinSCP in a powershell script to download all files. However, im not sure how to actually upload the files after. Do you have any suggestions? This is a snippet of my script currently: # Connect $session.Open($sessionOptions) # Download files $session.GetFiles($folder, $target).Check(). If i run this in my pipeline istead of release, is it possible to just add the downloaded files to the project before it gets created as an artifact? – sindrem Oct 27 '20 at 12:57
  • 1
    Please try https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/ftp-upload?view=azure-devops task – Krzysztof Madej Oct 27 '20 at 13:35
  • Hello! I have been able to run the PowerShell in my pipeline now, and i can see in my devops log that the files are being downloaded and added to a folder, but I'm not sure how to get the files from a folder in the pipeline, to the task: FtpUpload@2. Could you maybe take a look at my codepen where i have some comments on top? I would really appreciate it! https://codeshare.io/amBdLw – sindrem Oct 27 '20 at 16:53