Invoking subdirectory circleci - circleci

Hi does anyone know how I could trigger a specific folder circle's config? e.g. I'm using another config.yml to trigger an API call on the repository below and I would like to trigger the config.yml in folder-2 is there any way I could do this? Thanks
curl --request POST \
--url https://circleci.com/api/v2/project/gh/org/repo/pipeline \
--header "Circle-Token: $TOKEN" \
--header "content-type: application/json" \
--data '{"branch":"main"}'
My-Repo
|
+-- folder-1
| +-- .circleci
| | +--config.yml
+-- folder-2
| +-- .circleci
| | +--config.yml

Related

How to pass url at runtime using curl command which in encoded with ` sign?

I am trying to pass url in curl command using bash script
URL=www.google.com
response=``curl --location --request GET **${URL}** | jq . | grep buildVersion | awk '{print $2}' | sed 's/"//' | sed 's/"//' | sed 's/,//'``
echo $URL
The command in response variable is encoded with `
Is there a way I can send URL variable at runtime ?
This works fine for me
response=``curl --location --request GET www.google.com/data | jq . | grep buildVersion | awk '{print $2}' | sed 's/"//' | sed 's/"//' | sed 's/,//'`
Note : URL is sample site
I want to pass url at runtime I tried sending the --url parameter

Unable to add a group member using microsoft graph api in a bash script

If I run below http script from the graph.microsoft.com docs, it works fine.
POST https://graph.microsoft.com/v1.0/groups/9746dce-f530182/members/$ref
Content-type: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6Il9Y-pCiTwLhttVX5wg
{
"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/e7cb-2f96bba6"
}
where:
9746dce-f530182 = group-id,
e7cb-2f96bba6 = user-id and
eyJ0eXAiOiJKV1QiLCJub25jZSI6Il9Y-pCiTwLhttVX5wg = auth-token
I would like to run this as a bash script, so that I can automate the token generation and the POST call. My script looks like so.
CLIENT_ID='283f4d25-87bde0ef'
TENANT_ID='2d987312-a4ff5ea0'
CLIENT_SECRET='XSY8Q~4Ls-ahi'
GROUP_ID="9746dc-00182"
USER_ID='e7cb46-bbbba6'
AT_URL="https://login.microsoftonline.com/${TENANT_ID}/oauth2/token"
auth_response=$(curl -X POST -d 'grant_type=client_credentials&client_id='${CLIENT_ID}'&client_secret='$CLIENT_SECRET'&resource=https://graph.microsoft.com' $AT_URL | jq .)
token="$(echo $auth_response | jq -r .token_type) $(echo $auth_response | jq -r .access_token)"
curl -H "Authorization: $token" -H "Content-type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'$USER_ID'"}' "https://graph.microsoft.com/v1.0/groups/$GROUP_ID/members/$ref"
But this fails with the below error. What am I missing?
{"error":{"code":"Request_BadRequest","message":"Unsupported resource type 'DirectoryObject' for operation 'Create'.","innerError":{"date":"2022-05-25T11:24:21","request-id":"e189dc-063e","client-request-id":"e189d-2e42063e"}}}
I managed to fis the issue by changing the last line of the script to the following. The problem was that the $ref at the end of the URL was treated as a bash variable.
curl -H "Authorization: $token" -H "Content-Type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'${USER_ID}'"}' 'https://graph.microsoft.com/v1.0/groups/'$GROUP_ID'/members/$ref'
Hope this helps someone else.
The final script looks like below
CLIENT_ID='283f4d25-87bde0ef'
TENANT_ID='2d987312-a4ff5ea0'
CLIENT_SECRET='XSY8Q~4Ls-ahi'
GROUP_ID="9746dc-00182"
USER_ID='e7cb46-bbbba6'
AT_URL="https://login.microsoftonline.com/${TENANT_ID}/oauth2/token"
auth_response=$(curl -X POST -d 'grant_type=client_credentials&client_id='${CLIENT_ID}'&client_secret='$CLIENT_SECRET'&resource=https://graph.microsoft.com' $AT_URL | jq .)
token="$(echo $auth_response | jq -r .token_type) $(echo $auth_response | jq -r .access_token)"
curl -H "Authorization: $token" -H "Content-Type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'${USER_ID}'"}' 'https://graph.microsoft.com/v1.0/groups/'$GROUP_ID'/members/$ref'

Prometheus: filter query based on another metric

Say I have two metrics in prometheus, both counters:
requests_processed_total
requests_failed_total
They both have a matching service label. Example:
requests_processed_total{service="news"} 1097
requests_processed_total{service="store"} 487
requests_failed_total{service="news"} 23
requests_failed_total{service="store"} 89
How to query the requests_failed_total, but only for services whose request_processed_total > 1000.
I'm expecting the following response:
requests_failed_total{service="news"} 23
# Note that the "store" service is excluded
requests_failed_total and on(service) requests_processed_total > 1000
https://prometheus.io/docs/prometheus/latest/querying/operators/#logical-set-binary-operators
https://prometheus.io/docs/prometheus/latest/querying/operators/#one-to-one-vector-matches
If you are using Grafana you can do the following:
(1) Create a dashboard
(2) Click on Dashboard settings > Variables > New
(3) Create a variable with the following:
Name = service
Type = Query
Data source = Prometheus
Query = query_result(request_processed_total>5)
Regex = /service="(.*)"/
(4) Use the "service" variable to show the "requests_failed_total" metrics in any panel (you can also use the "repeat for " Grafana feature.
You can use the HTTP API to do this.
The following command will find services with request_processed_total>1000:
curl --silent --user USER:PASS --globoff --request GET "https://PROMETHEUS-SERVER/query?query=request_processed_total>1000" | jq --raw-output '.data.result[].metric.service'
And the following command will show requests_failed_total for a given service:
curl --silent --user USER:PASS --globoff --request GET "https://PROMETHEUS-SERVER/query?query=request_failed_total{service=\"SERVICE\"}" | jq --raw-output '.data.result[].value[1]'
So if you take both you get what you want:
for s in $(curl --silent --user USER:PASS --globoff --request GET "https://PROMETHEUS-SERVER/query?query=request_processed_total>1000" | jq --raw-output '.data.result[].metric.service')
do
curl --silent --user USER:PASS --globoff --request GET "https://PROMETHEUS-SERVER/query?query=request_failed_total{service=\"$s\"}" | jq --raw-output '.data.result[] | .metric.service + " " + .value[1]'
done

How to Get All Tags from Docker Hub (Private Repositories) as Shell Script

I have one shell script when i execute it showing only 64 tags from 300 tags docker hub.
Here is the below command which i'm executing in shell script through curl.
IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${HUB_TOKEN} https://hub.docker.com/v2/repositories/$username/issues/tags/?page_size=300" | jq --raw-output '.results[] | .name')
Even after giving page_size also it is not showing my all tags
Note :- Tags using for Private Repositories
Please help me how can i solve it
Try API version 1 which help me to get all the tags
https://registry.hub.docker.com/v1/repositories/mysql/tags open in browser and you can modify it as per your need
Or have a look to Github https://gist.github.com/robv8r/fa66f5e0fdf001f425fe9facf2db6d49 This is exactly what you want
UPDATE
Add this in a shell script file
#!/usr/bin/env bash
docker-tags() {
arr=("$#")
for item in "${arr[#]}";
do
tokenUri="https://auth.docker.io/token"
data=("service=registry.docker.io" "scope=repository:$item:pull")
token="$(curl --silent --get --data-urlencode ${data[0]} --data-urlencode ${data[1]} $tokenUri | jq --raw-output '.token')"
listUri="https://registry-1.docker.io/v2/$item/tags/list"
authz="Authorization: Bearer $token"
result="$(curl --silent --get -H "Accept: application/json" -H "Authorization: Bearer $token" $listUri | jq --raw-output '.')"
echo $result
done
}
docker-tags "<YOUR_DOCKER_IMAGE_NAME>"
Replace <YOUR_DOCKER_IMAGE_NAME> with your docker image.
have a look to this for more info Listing the tags of a Docker image on a Docker hub through the HTTP API

Generate JIRA release note through a jenkins job without plugins

I know that this is possible through the JIRA-JENKINS plugin. But I'm not an administrative user neither in JIRA nor Jenkins. Therefore I want to know is it possible to generate JIRA release note through a jenkin job without installing any plugins to JIRA or JENKINS?
Ok, I did it just now, here is my solution (that is a mix of several partial solution I have found googling):
In your deploy jobs, add a shell execution step at the end of the job and replace all parameters of the following script with correct values
version=<your_jira_version> ##(for example 1.0.71)
project_name=<your_jira_project_key> ##(for example PRJ)
jira_version_id=$(curl --silent -u <jira_user>:<jira_password> -X GET -H "Content-Type: application/json" "https://<your_jira_url>/rest/api/2/project/${project_name}/versions" | jq "map(select(.[\"name\"] == \"$version\")) | .[0] | .id" | sed -e 's/^"//' -e 's/"$//')
project_id=$(curl --silent -u <jira_user>:<jira_password> -X GET -H "Content-Type: application/json" "https://<your_jira_url>/rest/api/2/project/${project_name}" | jq .id | sed -e 's/^"//' -e 's/"$//')
release_notes_page="https://<your_jira_url>/secure/ReleaseNote.jspa?version=${jira_version_id}&styleName=Text&projectId=${project_id}"
release_notes=$(curl --silent -D- -u <jira_user>:<jira_password> -X GET -H "Content-Type: application/json" "$release_notes_page")
rm -rf releasenotes.txt
echo "$release_notes" | sed -n "/<textarea rows=\"40\" cols=\"120\">/,/<\/textarea>/p" | grep -v "textarea" > releasenotes.txt
You can use the maven-changes-plugin. You have to create a small maven project (doesn't need any sources) and include the plugin in the plugins section with the necessary configuration (see here: http://maven.apache.org/plugins/maven-changes-plugin/jira-report-mojo.html)
Then you create a Jenkins job, and just execute the maven goals you need (most probably just "mvn changes:jira-report").

Resources