How do you specify the sourceBranch for a Run of Pipelines via the REST API? - api

I've been trying to run a pipeline for a particular branch of the repository I'm using.
In the UI, there is a convenient option, but I don't understand what to try in the request.
No matter what I do I always run from master.
How do I change that? I tried filling out the repository parameters but to no avail: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0#repositoryresourceparameters
Here is an example request:
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"previewRun": true,
"resources": {
"repositories": {
"refName": "refs/heads/<redacted>"
}
},
"runParameters":
{
"namespace" : "<redacted>",
"image" : "<redacted>",
"tag" : "<redacted>",
"package" : "<redacted>",
"version" : "8.4.4"
}
}'

From your screenshot, it seems that you are using the YAML pipeline.
I have tested your example , and the root cause of this issue is that the request body(data-raw) has some issues.
You could try my sample
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"stagesToSkip":[],
"resources":
{
"repositories":
{
"self":{"refName":"refs/heads/{Branchname}"}
}
},
"templateParameters":
{
"namespace":"{value}",
"image":"{value}",
"tag":"{value}",
"package":"{value}",
"version":"{value}"
},
"variables":{}
}'
Result:

For Http Request (you can test it with Postman)
1. Get pipeline api url like this
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1
Source: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1
Fill in your organization, project and pipelineId.
(all of this can be found in the link when you open your pipeline definition in Azure DevOps)
2. Add Basic Auth headers
key: Authorization, value:"Basic [your azure Person Access Token from Azure Dev Ops with Access to Pipeline goes here]"
Should look like this
"Basic OndzNWdz43FKfjdi98hjKDJFH8kkg9854HJKHF9D8RFEHui4387lkNXE="
And set content type to application/json
like this
key: Content-Type, value: application/json
3. Put this JSON Into Raw Body
{
"templateParameters":{
"inputName":"johnsmith"
},
"resources":{
"repositories":{
"self":{
"refName":"refs/heads/feature/#JIRATask01_Blabla"
}
}
},
"variables":{
}
}
Replace refName value with branch you want to run the pipeline for.
If you have multiple repo pipeline look into this topic (but i haven't tested that solution):
Azure DevOps API to Trigger Multi Repo changing branches

Related

Run a job via the rundeck API with parameters in postman

I am trying around with the Rundeck API. I was able to get a simple Job running. But now I am trying to run a job, that has a job option. The job option for this job is an IP, so Rundeck starts the Job only on this machine.
When I use the API, I don't know how to set the parameter. I am using the tool Postman, where I only receive the message "Job options were not valid: Option 'IP' is required".
I looked it up on the rundeck documentation and I found this for postman
In the rundeck documentation is this example:
argString: argument string to pass to the job, of the form: -opt value -opt2 value ....
How can I use it for my IP?
Using this Rundeck Job Definition:
- defaultTab: nodes
description: ''
executionEnabled: true
id: 9f04657a-eaab-4e79-a5f3-00d3053f6cb0
loglevel: INFO
name: HelloWorld
nodeFilterEditable: false
options:
- name: opt1
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
- exec: echo "hello ${option.opt1}"
keepgoing: false
strategy: node-first
uuid: 9f04657a-eaab-4e79-a5f3-00d3053f6cb0
And based on this, you can do it by putting the options in JSON format (json body) on Postman:
{
"options": {
"opt1":"world"
}
}
This is the code snipped in cURL format:
curl --location --request POST 'pop-os:4440/api/38/job/9f04657a-eaab-4e79-a5f3-00d3053f6cb0/run' \
--header 'X-Rundeck-Auth-Token: GuaoD6PtH5BhobhE3bAPo4mGyfByjNya' \
--header 'Content-Type: application/json' \
--header 'Cookie: JSESSIONID=node01tz8yvp4gjkly8kpj18h8u5x42.node0' \
--data-raw '{
"options": {
"opt1":"world"
}
}'
Check how looks on Postman.

How to invoke AWS lambda while running EventGateway locally

I am trying to invoke an AWS Lambda function from a locally running EventGateway (version: 0.9.1) instance. However, the subscription call is failing due to an "Event Type: http.request not found".
The lambda has been deployed independently using serverless framework, and the ARN has been injected in the registration call:
The lambda is just a hello world type of lambda listening for http request:
functions:
hello-world:
handler: bin/hello-serverless
events:
- http:
path: /hello
method: get
My function registration call looks like this:
curl --request POST \
--url http://127.0.0.1:4001/v1/spaces/default/functions \
--header 'content-type: application/json' \
--data \
'{"functionId": "helloserverless", "type": "awslambda", "provider":{ "arn": "<lambda-arn>", "region": "ap-southeast-2", "accessKeyId": "<my-access-key>", "secretAccessKey": "<my-secret-key"}}'
Now, when I try to subscribe to an event:
--url http://127.0.0.1:4001/v1/spaces/default/subscriptions \
--header 'content-type: application/json' \
--data '{"functionId": "helloserverless", "type": "sync", "path": "/hello", "method": "GET", "eventType": "http.request"}'
I get the following error:
{"errors":[{"message":"Event Type \"http.request\" not found."}]}
Any pointer to the right solution or working example is pretty much appreciated.
If you want to call a function like an endpoint you need to have your application running. There is a plugin called serverless-offline to help you on this.
In case you want to call your function using serverless options, the command is called INVOKE. https://serverless.com/framework/docs/providers/aws/cli-reference/invoke-local/

Segment.io HTTP API not collecting events

The documentation and help for this particular Segment.io is limited and sparse, so I hope it's OK to ask in here.
I have just set up a Segment.io workspace and a HTTP API source
Per the docs, I sent some POST requests (with Postman) to the https://api.segment.io/v1/track and https://api.segment.io/v1/page endpoints. The requests were structured like this:
curl -X POST \
https://api.segment.io/v1/track \
-H 'Accept: */*' \
-H 'Authorization: My4w3s0m3k3y' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Host: api.segment.io' \
-H 'Postman-Token: 474d7fbe-15af-43d2-b629-61e15945e662,2c3d5fbe-2c09-4fe6-b7ea-a04e3221201b' \
-H 'User-Agent: PostmanRuntime/7.11.0' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache' \
-H 'content-length: 117' \
-d '{
"userId": "abc123",
"event": "My tests",
"properties": {
"name": "test 1"
}
}'
which all returned a 200 response and the following message:
{
"success": true
}
However, when I got to my dashboard, no events have been recorded.
The debugger is also empty
What am I missing here?
It looks like your write key isn't base64 encoded. When you encode your write key, remember to add the : at the end of it, before it's encoded.
Also, for the Authorization key:value, be sure to add Basic before the encoded write key. So your Authorization key:value would look like:
Authorization: Basic {encoded write key}
An example from the segment documentation:
In practice that means taking a Segment source Write Key,'abc123', as the username, adding a colon, and then the password field is left empty. After base64 encoding 'abc123:' becomes 'YWJjMTIzOg=='; and this is passed in the authorization header like so: 'Authorization: Basic YWJjMTIzOg=='.
I have been dealing with the same issue.
I found the solution as Todd said.
You should add a header Authorization: Basic + base64 encoding write key.
So, you look for the Segment source setting and get the write key.
After that, i have used an online base64 encoding tool to encode my write key.
Finally, you should add this header (Authorization) with 'Basic' and the encoded write key.
You should be able to see the tracked event in the Debugging panel in Segment web page.
I hope this helps!
You can try this code
const { promisify } = require("util");
var Analytics = require("analytics-node");
var analytics = new Analytics("xxxxxxxxxxxxxxxxxxxxxxx", {
flushAt: 1,
});
const [identify, track] = [
analytics.identify.bind(analytics),
analytics.track.bind(analytics),
].map(promisify);
console.log("user id: ", req.body.event.app_user_id);
let app_user_id = req.body.event.app_user_id;
let period_type = req.body.event.period_type;
let expiration_at_ms = req.body.event.expiration_at_ms;
let ret = "Initial";
try {
await identify({
userId: app_user_id,
traits: {
period_type: period_type,
expiration_at_ms: expiration_at_ms,
},
});
ret = "Done : Sengment done";
} catch (err) {
console.log("err: ", err);
ret = "Error : " + err;
}
return {
rafsan: ret,
};
Try to clear your browser's cache or use a different browser. I had the same problem and worked for me.
Hope this helps.

How i can send message to individual Line User?

I want to send message to private user not in any bot or group. How i can send ?
Thanks in advance
Line have API to send to one private user.
curl -v -X POST https://api.line.me/v2/bot/message/push \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer {channel access token}' \
-d '{
"to": "U4af4980629...",
"messages":[
{
"type":"text",
"text":"Hello, world1"
},
{
"type":"text",
"text":"Hello, world2"
}
]
}'
See the documentation: https://developers.line.biz/en/reference/messaging-api/#send-push-message

Is there a way to automatically train Wit.ai?

I know Wit.ai engine can be trained by manually validate cases, but is there a way to train it with a set of defined inputs and outputs?
You can use the wat.ai API to create an intent entity:
curl -X "POST" "https://api.wit.ai/entities" \
-H "Authorization: Bearer [token]" \
-d "{\"id\":\"intent\",\"doc\":\"Describe the users overall intention\",\"lookups\":[\"trait\"]}"
and then train it with values:
curl -X "POST" "https://api.wit.ai/entities/intent/values" \
-H "Authorization: Bearer [token]" \
-d $'{
"value": "hello",
"expressions": [
"hi",
"hello",
"oi",
"bonjour",
"aloha"
]
}
you can probably look at the export format of one of your app and tweak it to import in a new app. https://wit.ai/docs/recipes#manage-link