How to get lines of code within post trigger using Xcode Server? - ios

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?

Related

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)

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?

Docker Hub Remtoe Build Triggers

https://docs.docker.com/docker-hub/builds/#remote-build-triggers
Docker hub now has a build system in place. One of the ways to trigger a container to be built is using Remote build triggers. COmmands such as the following:
$ curl --data build=true -X POST https://registry.hub.docker.com/u/svendowideit/testhook/trigger/be579c82-7c0e-11e4-81c4-0242ac110020/
Their website shows a few paramters that can be passed in. But does not explain their meaning, nor do they provide a list all possible parameters.
What are all the possible parameters and what are their meanings?
it works for branches for sure, not sure about tags:
curl -H "Content-Type: application/json" \
--data '{"source_type": "Branch", "source_name": "develop"}' \
-X POST "$DOCKERHUB_TRIGGER";
Try source_type = Tag

Wget to download excel from Jira automatically

I have tried the below commands to get the excel file automatically from jira but I'm getting different data other than the filter data.
wget --user username--password pass -O test.xls --ignore-length=on http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000;
curl -D my-output.xml -u upgrade:hjjKl801 -X GET -H "Content-Type: application/json" http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000
Please help me here.
You have to set correct encoding header gzip :
curl -D my-output.xml -u upgrade:secret -X GET -H "Content-Type: application/json" -H "Accept-Encoding: gzip" "http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000"
Some notes:
Remove password from your example
-D flag for curl dumps headers, not output. Did you mean -o maybe?
Content-Type header can be skipped
To be on the safe side, put the url in double quotes
You can copy request from Google Chrome using developer tools
I can't get Wget work in my environment (permission denied error; maybe because of SSO?) but following curl command .
"D:\DSUsers\uid41890\Tools\curl.exe" -o C:\Users\uid41890\Documents\JIRA\search.csv -u uid41890:password -X GET "http://jiraurl:port/sr/jira.issueviews:searchrequest-csv-current-fields/17899/SearchRequest-17899.csv"
No need for Header options as mentioned in #grundic's answer.
Replace -D by -o in your original command and change the output file format from xml to csv for example.
You must use -O flag as:
curl -o excel.xls -O -u upgrade:hjjKl801 -X GET -H "Content-Type: application/json" http://esjirq62.emea.nsn-net.net:8080/sr/jira.issueviews:searchrequest-excel-all-fields/70920/SearchRequest-70920.xls?tempMax=1000

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