Generate JIRA release note through a jenkins job without plugins - jenkins

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").

Related

Set a curl output to a variable in a Dockerfile

basically i'm doing a curl and grepping some stuff.
But, i want set the output of this curl to a variable, to then use it on another curl.
e.g:
curl -u asd:asd http://zzz:123/aa/aa.aaa?cmd=ls | grep -B1 -E '<bbb>[4-7]\d{8,}' | grep yyy | tail -n 1 | sed -n -e 's/.*<xxx>\(.*\)<\/xxx>.*/\1/p')
but then I want set the output to a var and use it:
RUN aaa=$(previous curl) && curl -u asd:asd http://$aaa.com
tried with ${aaa}, with "$aaa", etc... didn't work. any solutions?
UPDATE:
something wrong is happening in previous curl 'cause doesn't return the value. probably for not doing the curl
I fear you will not be able to acheive this, because from my understanding RUN statement is to execute a command. To store value you'll have use SET.
For me the following workaround helped
RUN export aaa=$(curl -u asd:asd http://$aaa.com);echo aaa;
You can add the downsteam commands that will use the variable aaa towards right of the semicolon

Decline Pull request in Bitbucket when Building fail in Jenkins

I have triggered a build in Jenkins after creating a new pull request in bitbucket.
I want to automatically decline the pull request right away when building fail in Jenkins.
How do I do it and how can I set up it.
Is it possible to use a shell script in your case?
Something like this:
#!/usr/bin/env bash
if test $1 -ne 0; then
curl https://api.bitbucket.org//2.0/repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}/decline \
-u $3:$4 \
--request POST \
--header 'Content-Type: application/json' \
--data '{}'
fi
exit $1
Then, you can call the script as:
chmod +x decline-pull-request.sh
decline-pull-request.sh $(status) $(pullRequestId) $(bitbucketUsername) $(bitbucketPassword)

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

display sh script output in confluence using jenkins

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?

Trigger jenkins job with parameters from shell

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

Resources