Create Jira issue from Jenkins - windows

Hi, I am trying to create a Jira issue through Jenkins on a windows slave. The console output is not showing any error, however, the Jira issue is not getting created. Below is the code:
pipeline {
agent { label 'windows'}
stages {
stage('Build') {
steps {
bat script {"""curl -u ${jira_username}:${jira_password} -X POST -H 'Content- Type:application/json' -d '{"fields":{"components":[{"id":"1"}],"fixVersions":[{"id":"2"}],"project":{"key":"KEY"},"summary":"summary","description":"description","issuetype":{"name":"Test"}}}' http://localhost:8080/rest/api/2/issue/"""}
}
}
}
}
The console output is:
D:\workspace\TestJob>curl -u username:password -X POST -H 'Content-Type:application/json' -d
'{"fields":{"components":[{"id":"1"}],"fixVersions":[{"id":"2"}],"project":
{"key":"KEY"},"summary":"summary","description":"description","issuetype":{"name":"Test"}}}'
http://localhost:8080/rest/api/2/issue/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 136 0 0 100 136 0 323 --:--:-- --:--:-- --:--:-- 326
It doesn't throw any errors but the issue is also not getting created.
However, The same code if I run on Linux slave then I get the below response and the issue is getting created.
+ curl -u 'username:password' -X POST -H Content-Type:application/json -d '{"fields":
{"components":[{"id":"1"}],"fixVersions":[{"id":"2"}],"project":
{"key":"KEY"},"summary":"summary","description":"description","issuetype":
{"name":"Test"}}}' http://localhost:8080/rest/api/2/issue/
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 255 0 87 100 168 115 223 --:--:-- --:--:-- --:--:-- 223
100 255 0 87 100 168 115 223 --:--:-- --:--:-- --:--:-- 223
{"id":"648","key":"KEY-35","self":"http://localhost:8080/rest/api/2/issue/648"}
As you can see the issue is getting created on Linux but not on windows. Requesting help to resolve this issue.

Resolved the issue
Firstly 'Content-Type: application/json' should be in double-quotes.
Putting it in single quote 'Content-Type: application/json' was actually giving 415 error code which I got to know after using -k -D- in the curl command
Secondly, I had to use double backslash in the data.
The command which actually worked is:
bat script {"""curl -u username:password --header "Content-Type:application/json" -X POST --data "{\\"fields\\":{\\"project\\":{\\"key\\":\\"KEY\\"},\\"summary\\":\\"summary\\",\\"description\\":\\"description\\",\\"issuetype\\":{\\"name\\":\\"Test\\"},\\"components\\":[{\\"id\\":\\"1\\"}],\\"fixVersions\\":[{\\"id\\":\\"2\\"}]}}" http://localhost:8080/rest/api/2/issue/"""}

Related

AWS Fail to set timeout on ALB, Service, Task

I've got an unexpected error, I guess it's about timeout.
Task takes time quite long. generally less than 1minute. There is no problem when it fininsh before 1 minute. But sometimes task takes more than 1 minute. Error occurs when it takes more than 1minute. Please see below.
[ec2-user#ip-000-00-0-00 ~]$ curl --location --request POST 'userid.ap-northeast-2.elb.amazonaws.com:port/service' -d "video.mp4" -o output.json -v
Note: Unnecessary use of -X or --request, POST is already inferred.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 172.31.74.35:5000...
* Connected to loadbalancer.ap-northeast-2.elb.amazonaws.com (000.00.00.00) port 0000 (#0)
> POST /service HTTP/1.1
> Host: userid.ap-northeast-2.elb.amazonaws.com:port
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Length: 37
> Content-Type: application/x-www-form-urlencoded
>
} [37 bytes data]
100 37 0 0 0 37 0 0 --:--:-- 0:00:59 --:--:-- 0* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Date: Tue, 19 Apr 2022 01:45:23 GMT
< Content-Type: application/octet-stream
< Content-Length: 0
< Connection: keep-alive
< Server: Python/3.7 aiohttp/3.7.4.post0
<
100 37 0 0 0 37 0 0 --:--:-- 0:01:00 --:--:-- 0
* Connection #0 to host loadbalancer.ap-northeast-2.elb.amazonaws.com left intactm left intact
With curl verbose option, I get 500 Internal Server Error at 0:00:59. How can I finish my task which takes more than 1minutes?
I've tried
increasing Health check grace period for ECS Service
increasing idle timeout of Load Balancer
increasing timeout and interval of Target group
curl options (like keep-alive, max-time)
My EC2 Instance
type : t2.micro
Amazon Linux
My Service
Service type : REPLICA
Launch type : FARGATE
My task in service
Network mode : awsvpc
Compatibilities : EC2, FARGATE
Requries compatibilities : FARGATE
EFS mounted
Docker
Appreciate,

curl from url and rename to random uuid

i have the following command to curl a list of urls but I want to rename the output files to something else, as the original name is really long and results in the error below:
command:
jq -r '… | .[]' | xargs -I{} curl -O {}
error:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0Warning: Failed to create the file
Warning: 270230751_944073806238863_7984852070388291566_n.jpg?stp=dst-jpg_e35&_n
Warning: c_ht=example.njrsnnkjnrjgngkrnngrggk&_nc_cat=111&_nc_ohc=Ch26T4U5kDIAX
Warning: 8viWsL&edm=AABBvjUBAAAA&ccb=7-4&ig_cache_key=MjczOTA2MDk4MDU3MTIyNjQ1N
0 92492 0 1 0 0 1 0 25:41:32 --:--:-- 25:41:32 1
curl: (23) Failed writing body (0 != 1)
how to pass some argument to curl so that it renames the file to a smaller name eg 16 digit uuid or something like njfnjsnf48u8 but not too common as there can be upto 1000 files being downloaded at once.
You can manipulate the {} variable that xargs uses in curl command to make it more unique. If you are sure that there are no duplicate urls in the input file then the following might work.
curl {} -o $(echo {}|base64)

curl call works, but still returns "Could not resolve host: POST"

I run following script in gitlab's job:
after-merge-to-release:
script:
- set -x
- >
curl\
--X POST --header 'PRIVATE-TOKEN:xyz' --header 'Content-Type:application/json'\
--data '{"id":"'$PROJECT_ID'","name":"'${MOST_RECENT_SPRINT_BRANCH//'origin/'/}'","allowed_to_push":[{"access_level":0}],"allowed_to_merge":[{"access_level":0}]}'\
https://git.xyz.net/api/v4/projects/"$PROJECT_ID"/protected_branches
I can confirm this command works (it adds a new protected branch to my project), but gitlab's output doesn't confirm it:
$ curl\ # collapsed multi-line command
++ echo '$ curl\ # collapsed multi-line command'
++ curl --X POST --header PRIVATE-TOKEN:xyz --header Content-Type:application/json --data '{"id":"123","name":"origin/sprint/48","allowed_to_push":[{"access_level":0}],"allowed_to_merge":[{"access_level":0}]}' https://git.xyz.net/api/v4/projects/123/protected_branches
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (6) Could not resolve host: POST
100 530 100 413 100 117 3152 893 --:--:-- --:--:-- --:--:-- 4045
Why it doesn't return the response from curl request and throws Could not resolve host: POST error?
The error is here:
--X POST
Use only a single dash before X to select the http method:
-X POST

Elasticsearch scroll query returning with error

I'm trying to run an elasticsearch query with scrolling. Here's what I'm trying to do, but it is not working. I'm following the instructions here: https://www.elastic.co/guide/en/elasticsearch/reference/6.7/search-request-scroll.html
$ curl -u $(whoami) -XPOST 'https://myhost.io/elasticsearch/_msearch?scroll=1m' --data-binary #query.json -H "kbn-version:6.7.1" | jq
Enter host password for user '<first.last>':
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 973 0 96 100 877 321 2933 --:--:-- --:--:-- --:--:-- 3254
{
"statusCode": 500,
"error": "Internal Server Error",
"message": "An internal server error occurred"
}
Does anyone know why this doesn't work? If I remove the '?scroll=1m', this query works just fine.
You just need to expand the size of the scroll which is set probably to a smaller size

How can I quiet all the extra text when using curl within a shell script?

Here's an example ip proxy checker shell script:
#!/bin/sh
while read IP
do
CURL=$(curl -x http://$IP -L http://icanhazip.com)
echo "$CURL"
done < ip.txt
But instead of a simple result like:
0.0.0.0
1.1.1.1
I get:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0.0.0.0
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
1.1.1.1
How can I quiet the extra stuff?
-s/--silent
Silent mode. Don't show progress meter or error messages. Makes Curl mute.
If this option is used twice, the second will again disable mute.
CURL=$(curl -s -x http://$IP -L http://icanhazip.com)

Resources