简体   繁体   中英

Retrieve COSMOS Connection String or Primary Key in javascript running in azure pipeline

I have created azure pipeline using classic editor and executes test.js file using pipeline. I need to retrieve azure COSMOS key which could be used in the js file.

Tried by installing Cosmos DB Key Retriever extension but it doesnt show ADD option in the pipeline.

How can this be resolved? How cosmos key be fetched within js file?

How can this be resolved? How cosmos key be fetched within js file?

We strongly suggest using a config.js file to set your app's configurations, including the PRIMARY KEY of Azure Cosmos DB. Check related official documents here: #1 , #2 , #3 .

It seems that you want to avoid writing the key directly in code, then you can consider:

1.Copy the primary key from this page in Azure Web portal, and then create a variable group in Azure Devops pipelines to store that value. (Change variable type to secret !)

Also you can choose to host that value using Azure key valut and then link secrets from an Azure key vault in current variable group. (If you don't want to host the value in Varibale group directly.)

2. Link the variable group to your current classic pipeline.

3.Then you can use Replace Token task to insert the value of your Primary key into the config.js or xx.js file. You should run your other tasks after this task so that you can use the key in your js file.

Assuming I have the variable TheKeyIfCosmos to store the primary key.

在此处输入图像描述

Then specifying this format in config.js file:

key: "#{TheKeyOfCosmos}#",

在此处输入图像描述

After running that task, the content in config.js would be real key: "xxxxxxxxxxxxxxxx", .

After above steps you can test/run your app with primary key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM