I would like to publish the output of bash script in confluence using jenkins, and everytime the page in confluence opened will the output updated. Is there any possibility to do that? thx
You can use Confluence Rest Api.
You can try this https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/
Example:
curl -u jira_username_login:jira_password -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"new page",
"space":{"key":"TST"},"body":{"storage":{"value":"<p>This is <br/> a new page</p>","representation":
"storage"}}}' http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
To get bash output:
How to set a variable to the output of a command in Bash?
Related
I'm trying to trigger the Jenkins build via curl command with additional parameter as described in the following image:
I'm using --data-urlencode json='{"parameter": [{"name":"text", "value":"develop:test"}]}' but it doesn't work.
curl -X POST --user "${userName}:${password}" -H "Jenkins-Crumb:33c13aed5548ad43bf5e2eb276cf21af" "JENKINS_URL/job/JOB_NAME/buildWithParameters" --data-urlencode json='{"parameter": [{"name":"text", "value":"develop:test"}]}'
JenKins still build with the default parameter instead:
Any solution? Thanks.
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
My current shell script is following:
#!/bin/sh
LINES_OF_CODE=10792
curl -i -X POST -H "Content-Type:application/json" http://a:bc#lb.mycompany.org/api/public/metrics/ -d '{"project_public_id":"myprojectid", "type":"loc", "value":'$LINES_OF_CODE', "platform":"ios"}'
but it is hardcoded... is there any way to count number of lines dynamically?
I am trying to trigger a trigger jenkins job from shell but as of now no sucess.I tried both these methods
curl -u ceadmin:ceadmin -X POST http://abc-lnx:8080/job/ci_demo/build --data token=ci_build -data-urlencode json='{"parameter": [{"name":"Branch", "value":"master"}, {"name":"verbosity", "value":"high"}]}'
curl -X POST http://abc-lnx:8080/job/ci_demo/buildWithParameters?token=ci_build&Branch=master
I have defined ce_admin as token in my job. also ce_admin is a admin user in Jenkins.Anonymous user do not have any permission other then read on jobs and views.
What am i missing?
This works for me:
#parameters:
username=user
password=password
jenkins_url=example.com/build
some_token=hi
job_name=dostuff
curl -u $username:$password -X POST https://$jenkins_url/job/$job_name/build\?token\=$some_token
So this should work for your example (I escaped "?", and "&"):
curl -u ceadmin:ceadmin -X POST http://abc-lnx:8080/job/ci_demo/buildWithParameters\?token=ci_build\&Branch=master
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").