[SOLVED] Why it is impossible to replace tokens in Azure DevOps CI?


This Content is from Stack Overflow. Question asked by Micky

I have issue with replacing tokens using the plugin (Replace Tokens) in Azure Devops. I have json file in my project, but I don’t want to store credentials there. Due to this I’ve created variables in Azure Pipelines Library and want to parse credentials from there directly during CI. Please see below part from yml file.

- task: replacetokens@3
  displayName: 'Replace tokens'
    targetFiles: |
    tokenPrefix: '$('
    tokenSuffix: ')'

Below my json file:

  "number": "$(number)"

And I am adding screenshot from Azure Pipelines Library where the credentials stored
azure pipelines library

P.S. I am not sure if my issue depend on the programming language or not, I guess not, but anyway please note that I am using Python and this is the simple part of code where I am trying to use variable which I defined in azure Pipelines Library:

import json

f = open('config.json')
data = json.load(f)

number_variable = data['number']

Here is the CI answer to me:

##[warning]  variable not found: number
 0 token(s) replaced out of 1
replaced 0 tokens out of 1 in 1 file(s) in 0.1 seconds.

Any suggestions?

Solution by Kevin Lu-MSFT

From your YAML sample, there is a problem with the syntax you are using to call the Variable Group. In this case, it will not able to use the variable in variable group.

  group: $(credgroup)

You can try to use the following format to call the Variable Group.

  - group: variablegroupname

Refer to this doc: variables.group definition

For more tutorials visit Jtuto.com

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 4.0.

people found this article helpful. What about you?