如何在下一个VSTS任务中获取输出变量的值?

时间:2019-04-21 15:47:42

标签: powershell build azure-devops continuous-integration azure-pipelines

我正在使用此命令在任务1中设置输出变量


//Table definition serverless.yml

resources:
  Resources:
    ConsentDynamoDBTable:
      Type: 'AWS::DynamoDB::Table'
      Properties:
        AttributeDefinitions:
          -
            AttributeName: domain
            AttributeType: S
          -
            AttributeName: ts
            AttributeType: N
        KeySchema:
          -
            AttributeName: domain
            KeyType: HASH
          -
            AttributeName: ts
            KeyType: RANGE
        ProvisionedThroughput:
          ReadCapacityUnits: 10
          WriteCapacityUnits: 10
        TableName: ${self:custom.tableName}


//THE QUERY

app.get("/consents/:domain/:startDate/:endDate", function (req, res) {

    const params = {
        TableName: DEV_TABLE,
        KeyConditionExpression: "#dom = :doma AND #tstamp BETWEEN :startDate AND :endDate",
        ExpressionAttributeNames: {
            "#dom": "domain",
            "#tstamp": "ts"
        },
        ExpressionAttributeValues: {
            ":doma":        req.params.domain,
            ":startDate":   req.params.startDate,
            ":endDate":     req.params.endDate
        }
    };
        console.log("PARAMS: ", params);
    dynamoDb.query(params, function(err, data){
        if (err) {
            res.status(400).json({ error: "Could not get user" });
        }
        if (data.Items) { // HERE COMES THE ERROR --> TypeError: Cannot read property 'Items' of null
            res.json(data.Items);
        } else {
            res.status(404).json({ error: "User not found" });
        }
    });
});

,并尝试使用以下命令访问此变量(在一系列任务中,任务3在任务1的下一个旁边)


console.log --> PARAMS:  { TableName: 'table-dev',
  KeyConditionExpression: '#dom = :doma AND #tstamp BETWEEN :startDate AND :endDate',
  ExpressionAttributeNames: { '#dom': 'domain', '#tstamp': 'ts' },
  ExpressionAttributeValues: 
   { ':doma': 'url.com',
     ':startDate': '1555857529129',
     ':endDate': '1555857536819' } }

2019-04-21 17:36:21.411 (+02:00)    c7f9720f-ea15-4e15-b508-9ffea47935dd    TypeError: Cannot read property 'Items' of null
    at Response.<anonymous> (/var/task/index.js:95:11)´´´

但是没有输出,所有变量的值都为空。

有什么主意吗?

1 个答案:

答案 0 :(得分:3)

等号和变量名之间有一个前导空格:

Write-Output ("##vso[task.setvariable variable= buildOutcome;]$buildOutcome")
#                                              ^ extraneous space

删除它:

Write-Output ("##vso[task.setvariable variable=buildOutcome;]$buildOutcome")