Configuring a bitbucket repository to "activate" pipelines - bitbucket-api

I have multiple repositories in a BitBucket project.
I wish to automatically create a bitbucket repository, and enable pipelines (setting the pipeline configuration should be easy, with pushing a bitbucket-pipelines.yml file).
How can I do it using the REST API?

The other answer's "enable pipelines" request did not work for me.
This is what worked:
curl -X PUT -is -u '<username>:<password>' -H 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/<username>/<slug>/pipelines_config \
-d '{
"enabled": true
}'

You can create a repository with the BitBucket REST API.
$ curl -X POST -H "Content-Type: application/json" -d '{
"scm": "git",
"project": {
"key": "Foo"
}
}' https://api.bitbucket.org/2.0/repositories/<username>/<repo_slug>
Push your bitbucket-pipelines.yml to your created repo.
curl https://api.bitbucket.org/2.0/repositories/<username>/<slug>/src \
-F /bitbucket-pipelines.yml=#bitbucket-pipelines.yml
Then enable pipeline for your project
curl -X PUT -is -u '<username>:<password>' -H 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/<username>/<repo_slug> \
-d '{
"enabled": true,
"type": "repository_pipelines_configuration"
}'
Finally, you can trigger a pipeline for the branch like so.
$ curl -X POST -is -u <username>:<password> \
-H 'Content-Type: application/json' \
https://api.bitbucket.org/2.0/repositories/<username>/<slug>/pipelines/ \
-d '
{
"target": {
"ref_type": "branch",
"type": "pipeline_ref_target",
"ref_name": "<branch_name>"
}
}'
References:
Repository API
Pipelines API

Related

Trying to use browserless ... getting "message: 'elements' is not allowed"

I'm trying to scrape an Amazon page with browserless:
curl -X POST \
"https://chrome.browserless.io/content?token=<token>" \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d ' {
"url": "https://www.amazon.com/gp/your-account/order-details/?orderID=114-5444651-3149007",
"elements": [{
"selector": "a",
}],
"cookies": [
<many cookies>
],
}'
but I keep getting:
[{"message":"\"elements\" is not allowed","path":["elements"],"type":"object.unknown","context":{"child":"elements","label":"elements","value":[{"selector":"a","timeout":10000}],"key":"elements"}}]%
If I exclude the elements object, it works fine but returns the entire 6,000 lines of <html>.
(What I actually want is document.getElementsByClassName('shipment')[0].innerText)
When I try the examples (from the docs) they work fine.
Its because elements only available for /scrape API
You are using /content

How to obtain time-entries for a project?

An api exists for obtaining all time-entries for a workspace, /workspaces/{workspaceId}/time-entries, and the ability to obtain time-entries for a user, /workspaces/{workspaceId}/user/{userId}/time-entries.
Can filtering be added to /workspaces/{workspaceId}/time-entries? Start Date would be nice.
Would be possible to add obtain time-entries for a project?
/workspaces/{workspaceId}/projects/{projectId}/time-entries, with filtering of course
For the new clockify report API, which is documented here (https://clockify.me/developers-api#tag-Reports), you can use following requests.
Filtering time entries by user and date:
curl --request POST \
--url https://reports.api.clockify.me/v1/workspaces/<YOUR WORKSPACE ID>/reports/summary \
--header 'content-type: application/json' \
--header 'x-api-key: <YOUR API KEY>' \
--data '{
"dateRangeStart": "2020-08-13T00:00:00.000Z",
"dateRangeEnd": "2020-08-13T23:59:59.000Z",
"summaryFilter": {"groups": ["USER", "TIMEENTRY"]},
"exportType": "JSON",
"users": {
"ids": ["<USER ID>"],
"contains": "CONTAINS",
"status": "ALL"
}
}'
All time entries for a certain project:
curl --request POST \
--url https://reports.api.clockify.me/v1/workspaces/<YOUR WORKSPACE ID/reports/summary \
--header 'content-type: application/json' \
--header 'x-api-key: <YOUR API KEY>' \
--data '{
"dateRangeStart": "2020-08-13T00:00:00.000Z",
"dateRangeEnd": "2020-08-13T23:59:59.000Z",
"summaryFilter": {"groups": ["PROJECT", "TIMEENTRY"]},
"exportType": "JSON",
"projects": {"ids" : ["<PROJECT ID>"]}
}'
If you remove the group TIMEENTRY you will just get the sums as result, not all the separate time entries.
Of course you can fetch all time entries for a project grouped by a user like this (filtering by project and grouping by USER:
"summaryFilter": {"groups": ["PROJECT", "USER", "TIMEENTRY"]},

helm hosted repo via CLI

I installed the helm repo plugin for nexus3
Now I want to create the helm hosted repo via RestAPI command, in the same way as I do for raw repository
# RAW Repository
curl -X POST "${NEXUS_URL}/service/rest/v1/script" \
--user "admin:admin123" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \"name\": \"create_raw_repo\", \"content\": \"repository.createRawHosted(args, 'default')\", \"type\": \"groovy\"}"
curl -X POST "${NEXUS_URL}/service/rest/v1/script/create_raw_repo/run" \
--user "admin:admin123" \
-H "accept: application/json" \
-H "Content-Type: text/plain" \
-d "raw-release"
# HELM Repo
curl -X POST "${NEXUS_URL}/service/rest/v1/script" \
--user "admin:admin123" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \"name\": \"create_helm_repo\", \"content\": \"repository.createHelmHosted(args, 'default')\", \"type\": \"groovy\"}"
curl -X POST "${NEXUS_URL}/service/rest/v1/script/create_helm_repo/run" \
--user "admin:admin123" \
-H "accept: application/json" \
-H "Content-Type: text/plain" \
-d "helm-demo-release"
The problem is that the repository.createHelmHosted method doesn't exists.
What is the correct way to do it?
From version 3.21 nexus support OOB the helm repo and has REST API to create the repo
http://you-nexus:8081/service/rest/beta/repositories/helm/hosted
curl -X POST "http://you-nexus:8081/service/rest/beta/repositories/helm/hosted" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
-d "{ \"name\": \"internal\", \"online\": true, \"storage\": { \"blobStoreName\": \"default\", \"strictContentTypeValidation\": true, \"writePolicy\": \"allow_once\" }, \"cleanup\": { \"policyNames\": \"weekly-cleanup\" }}"

how to curl with query string parameter in format of "filter[name]=foo"

Here is an api on my server:
https://server/api/v1/products?filter[name]=foo
this works well when I access it via browser, and it works well with the following two methods:
$ cat /tmp/x
{"filter": {"name": "foo"}}
$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : -H 'Content-Type: application/json' -d "#/tmp/x" https://server/api/v1/products
{"name": "foo", ...}
$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : -d "filter[name]=foo" https://server/api/v1/products
{"name": "foo", ...}
Now I'm trying to do it with:
$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : https://server/api/v1/products?filter[name]=foo
$ echo $?
3
it fails with error code 3, which stands for "URL malformed. The syntax was not correct."
How should I specify the query string parameters in the url?
The query string needs to be URL encoded so it has to look like this:
https://server/api/v1/products?filter%5Bname%5D=foo
asciitable.com.

Custom ceilometer metrics

I am trying to add a custom metric to ceilometer via API and have success in adding new metric and new data, but I have fail when try to see this new metric in dashboard.
The comand I gave use:
Get a token:
curl -i -X POST http://controller:35357/v2.0/tokens -H "Content-Type: application/json" -H "User-Agent: python-keystoneclient" -d '{"auth": {"tenantName": "test", "passwordCredentials": {"username": "admin", "password": "password"}}}' ;
Take token:
mysql -e 'use keystone; select id from token;' | tail -n 1
Add custom metric with data:
curl -X POST -H 'X-Auth-Token: TOKEN' -H 'Content-Type: application/json' -d '[{"counter_name": "test","user_id": "admin_user_id","resource_id": "Virtual_machine_ID","resource_metadata": {"display_name": "my_test","my_custom_metadata_1": "value1","my_custom_metadata_2": "value2"},"counter_unit": "%","counter_volume": 10.57762938230384,"project_id": "VM_tenant_ID","counter_type": "gauge"}]' http://controller:8777/v2/meters/test
All of that comands have success =)
Checking with comands like:
ceilometer sample-list -m test
ceilometer meter-list |grep test
ceilometer statistics -m test
they are returns the data that I have input before. But when I am open dashboard with Resources Usage Overview I can't see new metric in a list.
So I can't found a desicion of my problem. Anybody can help me?

Resources