I have used azure devops variable group variables to define my appsettings properties. However, I could not use an array as a value for one of my appsettings properties.
Here is a screenshot of what i am trying to do:
But it appears on the appsettings.json as follows which results in a 500 internal server error Value cannot be null. Parameter name: collection
"AzureAd": {
"Instance": "https://login.microsoftonline.com",
"ClientId": "",
"TenantId": "",
"Audience": "[ https://api.doesnotexist.com ]"
}
The code in Startup.cs that is failing is as follows:
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(o =>
{
o.Authority = $"{azureADSettings.Instance}/{azureADSettings.TenantId}/";
o.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = true,
ValidAudiences = new List<string>(azureADSettings.Audience),
};
});
Please Refer to this doc:
All variables are stored as strings and are mutable. The value of a variable can change from run to run or job to job of your pipeline.
In Azure Devops, Variables are String type by default. And we couldn'change it.
So when you define an array in variable, it will pass the array as a string to your appsettings.json file.
To solve this issue, you need to change to use Parameters. The parameter supports the value of the input array type.
Here is an example:
parameters:
- name: 'param'
type: object
default: [123,234,456]
steps:
- ${{ each p in parameters.param }}:
- script: echo ${{ p }}
Note: Parameters can only be used in YAML pipeline.
You can also set collection using the variables as explained in the microsoft documentation
By adding the index of the element in the variable name
example
Related
Is it possible to add a pipeline variable of array type in ADO pipeline? I’m trying to add a pipeline variable of array type with these values:
[
{ name: abc, id: 123 },
{ name: def, id: 456 }
]
Pipeline variable doesnot support complex type, all variables are stored as strings. You can try below workarounds depending on how you use the variable in your pipeline.
1, If you want to reference the variable in other task. You can define the variable as runtime parameters instead of pipeline variables. You can define the parameter like below:
parameters:
- name: Ids
type: object
default:
- name: abc
value: 123
- name: efg
value: 456
Then you can refer to the parameter using syntax like this :${{parameters.Ids[0].name}}
steps:
- powershell: |
echo "${{parameters.Ids[0].name}}"
echo "${{parameters.Ids[0].value}}"
2, If you use the variable in a script task. You can save the value to json string. And convert to json object in the script. See below example:
First, Save the value to json string('[{"name":"abc", "value":111},{"name":"efg", value:222}]') to the pipeline variable:
Then, Convert to json object in the script task. See below example in powershell task:
steps:
- powershell: |
$ids = $(ids) | convertfrom-json
echo $ids[0].name
No pipeline variables are strings. There is no way at the moment to have variable of complex type. Plese check this topic on developer community - Variables in YAML pipeline are not allowing to define array
Yaml variables have always been string: string mappings. Instead of using variable, you may consider Parameters.
parameters:
- name: abc
type: string
default: 123
- name: def
type: string
default: 456
……
I want to pass the value set by core.setOutput to different steps at once. So I passed the outputs of the step hello-action to another step:
//index.js
const core = require("#actions/core");
core.setOutput("res1","res1");
core.setOutput("res2","res2");
core.setOutput("res3","res3");
jobs:
build:
runs-on: ubuntu-latest
name: Hello
steps:
- name: Checkout
uses: actions/checkout#master
- name: run hello action
id: hello-action
run: node index.js
- name: run hello2 action
id: hello2-action
run: node index2.js
with:
outputs: ${{ steps.hello-action.outputs }}
point is this.
outputs: ${{ steps.hello-action.outputs }}
The type of the above value is an object, but I couldn't access the key inside the object.
//index2.js
const core = require("#actions/core");
const outputs = core.getInput("outputs");
console.log("hello2 outputs:", outputs); //result is [object Object]
console.log("hello2 outputs:", outputs.res1); //result is undefined
Is there a way to pass arguments in bulk?
Objects cannot be transferred to output from action, only strings.
Therefore, when passing an object from a custom action toString() method will be called on it. As a result, you get your [object Object] already at the moment of performing this action here:
- name: run hello action
id: hello-action
run: node index.js
To transfer data structures from a custom action, cast object to JSON string using JSON.stringify() method.
first action
//index1.js
const obj = {
field1: "value1",
field2: "value2",
}
core.setOutput("outputs", JSON.stringify(obj));
And in your second step, parse the JSON string
second action
//index2.js
const core = require("#actions/core");
const outputs = JSON.parse(core.getInput("outputs"));
This should help you.
My end goal is to create a policy document from a cloudformation script. I want to have one script where the parameter is selected and that value is used to in the name of the resource.
"arn:aws:dynamodb:us-east-1:12345678:table/monit-${dev}/stream/*"
where ${dev} is a parameter value
Parameters:
Environment:
Default: dev
Description: Leveraged for environment tagging.
Type: String
AllowedValues:
- dev
- tst
- qa
- stg
- prd
I want to try something like the following but don't know how to add the Ref Environment from the parameter or is there some other method?
'Fn::Sub': 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}'
So I don't end up have to create a bunch of different scripts
PolicyDocument:
Statement:
- Effect: Allow
Action:
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
- dynamodb:Scan
#This will need to changed for other tables
Resource:
- "arn:aws:dynamodb:us-east-1:12345678:table/monit-dev/stream/*"
- "arn:aws:dynamodb:us-east-1:12345678:table/monit-dev"
If i understood you correctly, You can use Fn::Join to add the "Environment" value. You dont use Ref of the value it self.
The intrinsic function Ref returns the value of the specified parameter or resource.
When you specify a parameter's logical name, it returns the value of the parameter.
When you specify a resource's logical name, it returns a value that you can typically use to refer to that resource, such as a physical ID.
json example:
"CustomInstanceProfileArn": {
"Fn::Join": [
"", ["arn:aws:iam::", {
"Ref": "AWS::AccountId"
},
":instance-profile/", {
"Ref": "InstanceProfile"
}
]
]
},
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html
I'm developing a new visual in PowerBI and first defining visual capabilities.
Even, the samples show me that, for example, gauge.capabilities.ts file like this.
export var gaugeCapabilities: VisualCapabilities = {
dataRoles: [
{
name: gaugeRoleNames.y,
kind: VisualDataRoleKind.Measure,
displayName: data.createDisplayNameGetter('Role_DisplayName_Value'),
}, {
name: gaugeRoleNames.minValue,
kind: VisualDataRoleKind.Measure,
displayName: data.createDisplayNameGetter('Role_DisplayName_MinValue'),
}, {
name: gaugeRoleNames.maxValue,
kind: VisualDataRoleKind.Measure,
displayName: data.createDisplayNameGetter('Role_DisplayName_MaxValue'),
}, {
name: gaugeRoleNames.targetValue,
kind: VisualDataRoleKind.Measure,
displayName: data.createDisplayNameGetter('Role_DisplayName_TargetValue'),
}
],
I want to define custom display names like "From", "To". And when I trying to input it as "raw" in the dataRoles like:
dataRoles: [
{
name: gaugeRoleNames.y,
kind: VisualDataRoleKind.Measure,
displayName: 'From',
}, { ...
And it works.
But I think this is out of coding requirements. Is there any way to define custom display name getter like:
displayName: data.createDisplayNameGetter('Role_DisplayName_From')
I tried. But it doesn't work.
Does anyone have same issue and solve this problem?
Defining a function for displayName allows a visual to fetch a localized string.
The data.createDisplayNameGetter function returns a lambda that does a resource string lookup in our PowerBI.resx resources.
The custom visuals don’t currently have a way to do extend our PowerBI.resx. So you can either hard-code (as you’ve done), or you can define your own function that does your own resource lookup.
Using Mongo and Meteor with CoffeeScript, I'm trying to save a document with one Object:
Test = new SimpleSchema(
tag:
type: Object
)
And the insert:
test1 = new Meteor.Collection("test", { schema: Test})
test1.insert({ tag: {"name": "campus"} })
Result: a document gets saved in the database but the "tag" field is never set.
Couple of different troubleshooting steps I've taken:
Changing the data type to String works and the "tag" field gets set. However, I want to reference a tag property without having to parse the string every time.
Adding a collection without the schema saves the Object exactly how I want:
test2 = new Meteor.Collection("test2")
test2.insert({ tag: {"name": "campus"} })
EDIT: Fixed using the blackbox: true flag. See below answer for clarification.
Test = new SimpleSchema(
tag:
type: Object
blackbox: true
)
According to SimpleSchema docs, all defined properties must pass validation. So any Object data type without properties is treated as an empty Object unless you add the blackbox: true flag.
Source: http://atmospherejs.com/aldeed/simple-schema#blackbox
If you have a key with type Object, the properties of the object will be validated as well, so you must define all allowed properties in the schema. If this is not possible or you don't care to validate the object's properties, use the blackbox: true option to skip validation for everything within the object.
I use simple schema and create my models of the following way, and I don't have any problem.
Test = new Meteor.Collection("test", {
schema: new SimpleSchema({
ownerId: {
type: String,
},
dateAdd: {
type: Date,
}
})
})
Test.insert({ownerId:"123",dateAdd:"..."})
In Coffee Script
Test = new Meteor.Collection("test",
schema: new SimpleSchema(
ownerId:
type: String
dateAdd:
type: Date
)
)