2

We have few existing Azure Function Apps with multiple functions inside, and we need to move all of them to source control.

I've successfully created an empty repo and connected Azure Functions to it via "Deployment Center",
but after clicking on "Sync" nothing is added to the repo (it remains empty)

Pic.1: Empty repo after sync

even though the message appears about successful sync

Pic.2: Deployment center sync success

also after integration, all the existing azure functions stopped being editable and runnable

Pic.3: Read only Azure Function

So, is there a way to move all the existing functions to the repo, and continue development on them?

1
  • 1
    I don't think sync will actually perform a two-way sync. Only pull code from the repo and deploy it into your Function Commented Sep 9, 2019 at 9:07

3 Answers 3

3

For continuous deployment to succeed, your directory structure must be compatible with the basic folder structure that Azure Functions expects. The code for all the functions in a specific function app is located in a root project folder that contains a host configuration file and one or more subfolders. Each subfolder contains the code for a separate function.

FunctionApp
 | - host.json
 | - Myfirstfunction
 | | - function.json
 | | - ...  
 | - mysecondfunction
 | | - function.json
 | | - ...  
 | - SharedCode
 | - bin

Only when you follow this structure in your repo the CI/CD will work as expected.

Once you have commited all your functionapp code to your repo try following the steps from here and it should work as expected.

Sign up to request clarification or add additional context in comments.

Comments

1

As far as I know the sync will not pull down code into the repo. If you navigate to the function app in the portal there is a "Download App Content" button in the overview section. You can then decide if you want the site content or a Visual Studio Project containing your code. This will produce a zip file with your function app code in.

The read change in your question occurs as changes should now come from continues deployment pipeline. You can turn read only off by going into the Function app overview page and changing "Function app edit mode" to read/write.

Comments

0

(Building on the answers provided by HariHaran and user3755846.) Sync is 1-way, from the Azure Repo to the Azure Function. Here's one way to copy the Function Files over to the Azure Repo:

  1. Go to your Function: Click 'Overview' -> 'Download app content' -> 'Site content'. It will give you a zip file.

enter image description here

  1. Get your Git URL and Credentials: On your Azure Repo: Click 'Repos' -> 'Clone' -> 'Generate Git Credentials'

enter image description here

  1. Setup your work environment. We're using Azure CloudShell in the examples below.
PS /home/repo> git config --global user.name "myFirstName myLastName"
PS /home/repo> git config --global user.email "[email protected]"

PS /home/repo> git clone https://[email protected]/myrepo/myproject/_git/myproject
Cloning into 'myproject'...

Password for 'https://[email protected]': 
remote: Azure Repos
remote: Found 6 objects to send. (17 ms)
Unpacking objects: 100% (6/6), 1.57 KiB | 1.57 MiB/s, done.

PS /home/repo> ls
myproject

PS /home/repo> cd ./myproject/

PS /home/repo/myproject> ls
README.md
  1. Unzip the project files you downloaded in Step1
PS /home/repo/myproject> unzip ./myfunction.zip
Archive:  ./myfunction.zip
  inflating: host.json               
  inflating: mycode/function.json  
  inflating: mycode/readme.md  
  inflating: mycode/run.ps1  
  inflating: profile.ps1             
replace README.md? [y]es, [n]o, [A]ll, [N]one, [r]ename: y
  inflating: README.md               
  inflating: requirements.psd1       

PS /home/repo/myproject> rm ./myfunction.zip

PS /home/repo/myproject> ls
host.json  mycode  profile.ps1  README.md  requirements.psd1
  1. Commit the changes to your repository.
PS /home/repo/myproject> git add .

PS /home/repo/myproject> git commit
[main b065464] Initial Project Commit
 6 files changed, 74 insertions(+)
 create mode 100644 mycode/function.json
 create mode 100644 mycode/readme.md
 create mode 100644 mycode/run.ps1
 create mode 100644 host.json
 create mode 100644 profile.ps1
 create mode 100644 requirements.psd1

PS /home/repo/myproject> git push -u origin main
Password for 'https://[email protected]': 
Enumerating objects: 10, done.
Counting objects: 100% (10/10), done.
Delta compression using up to 2 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 2.24 KiB | 573.00 KiB/s, done.
Total 9 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (9/9) (6 ms)
remote: Storing packfile... done (30 ms)
remote: Storing index... done (43 ms)
To https://dev.azure.com/myrepo/myproject/_git/myproject
   e7cf6e0..b065464  main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
  1. Go back to your repo. You should now see your files!

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.