I am using Jasper REST API to publish reports on Jasper Server.
Below are the scenarios:
When I upload the .JRXML file from POSTMAN and then create a report from POSTMAN using the JRXML. It works.
When I upload the .JRXML file from POSTMAN and then create a report from Jenkins using the JRXML. It works.
When I upload the .JRXML file from Jenkins and then create a report from Jenkins using the JRXML. It gives me HTTP 500 Error
When I upload the .JRXML file from Jenkins and then create a report from Jenkins using the JRXML. It gives me HTTP 500 Error.
I have even tried with cURL and it works fine. Its just the Jenkins where it gives the error. I have tried a lot of things but it has no outcome.
cURL from POSTMAN:
#To upload JRXML
curl --location --request POST 'https://server-url/jasperserver-pro/rest_v2/resources/Reports/' \
--header 'Content-Type: application/jrxml' \
--header 'Content-Disposition: attachment; filename=form.jrxml' \
--header 'Content-Description: Uploaded jrxml file POSTMAN' \
--header 'Authorization: Basic %Base64 Creds%' \
--data-binary 'report-templates/form.jrxml'
#To create report
curl --location --request POST 'https://server-url/jasperserver-pro/rest_v2/resources/Reports' \
--header 'Content-Type: application/repository.reportUnit+xml' \
--header 'Authorization: Basic Base64 Creds' \
--data-raw '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<reportUnit>
<description/>
<label>new_report1</label>
<permissionMask>1</permissionMask>
<uri>/Reports</uri>
<version>0</version>
<dataSourceReference>
<uri>/Data_Sources/mysql</uri>
</dataSourceReference>
<alwaysPromptControls>true</alwaysPromptControls>
<controlsLayout>popupScreen</controlsLayout>
<inputControlRenderingView/>
<jrxmlFileReference>
<uri>/Reports/form.jrxml</uri>
</jrxmlFileReference>
</reportUnit>'
JenkinsFile:
pipeline {
agent any
parameters{
string(defaultValue: 'form5_report', description: 'Provide the name of JRXML file, without the extension that should be used to create report. Defaults to form5_report.', name: 'JRXML_FILE', trim: false)
string(defaultValue: "${params.JRXML_FILE}.${BUILD_NUMBER}", description: 'Provide a name for the generated report. By default, it would be same as JRXML with BUILD_NUMBER.', name: 'TESTUNIT', trim: false)
}
environment{
JRXML_FILE = "${JRXML_FILE}.jrxml"
def XML = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<reportUnit>
<description/>
<label>${TESTUNIT}</label>
<permissionMask>1</permissionMask>
<uri>/Reports</uri>
<version>0</version>
<dataSourceReference>
<uri>/Data_Sources/mysql</uri>
</dataSourceReference>
<alwaysPromptControls>true</alwaysPromptControls>
<controlsLayout>popupScreen</controlsLayout>
<inputControlRenderingView/>
<jrxmlFileReference>
<uri>/Reports/${JRXML_FILE}</uri>
</jrxmlFileReference>
</reportUnit>"""
}
stages {
stage('File Check') {
steps {
script {
String url = "https://server-url/jasperserver-pro/rest_v2/resources?q=${JRXML_FILE}"
def (String code) =
sh(script: "curl -s -o /dev/null -w '%{http_code}' -H 'Authorization: Basic base64 creds' $url", returnStdout: true).trim().tokenize("\n")
if(code == '200'){
stage ('Create Report'){
sh '''
curl --location --request POST 'https://server-url/jasperserver-pro/rest_v2/resources/Reports' \
--header 'Content-Type: application/repository.reportUnit+xml' \
--header 'Authorization: Basic base64 creds' \
-d "$XML"
'''
}
}else{
stage('SCM Checkout'){
git branch: 'branchname',
credentialsId: 'git',
url: 'repo_URL'
}
stage('Upload JRXML File to JasperServer'){
sh '''
curl --location --request POST 'https://server-url/jasperserver-pro/rest_v2/resources/Reports/' \
--header 'Content-Type: application/jrxml' \
--header "Content-Disposition: attachment; filename=${JRXML_FILE}" \
--header 'Content-Description: Uploaded jrxml file' \
--header 'Authorization: Basic base64 creds' \
--data-binary "$WORKSPACE/${JRXML_FILE}"
'''
}
stage('Create Report'){
sh '''
curl --location --request POST 'https://server-url/jasperserver-pro/rest_v2/resources/Reports' \
--header 'Content-Type: application/repository.reportUnit+xml' \
--header 'Authorization: Basic base64 creds' \
-d "$XML"
'''
}
}
}
}
}
}
}
What am I doing wrong? Any help is greatly appreciated.
Alright, so I got it working.
Apparently, I was unaware of the fact that when referencing/passing a file with --data-binary option, you need to prepend it with the '#' symbol.
Therefore changing line no.61 from --data-binary "$WORKSPACE/report-templates/${JRXML_FILE}" to --data-binary "#$WORKSPACE/report-templates/${JRXML_FILE}" did the trick. Otherwise, it was just saving the absolute path as the content of the file and not the actual XML data.
Related
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'
We have a pipeline where we need to invoke external API with Authorization header, whose value comes from Jenkins secret, which has been pre-configured.
When implemented as below, Jenkins complains for string interpolation.
withCredentials([string(credentialsId: '<SECRETNAME>', variable: 'Token')]) {
sh """curl --location --request POST 'https://abc.example.com/api/endpoint' \
--header 'Authorization: Bearer ${Token}' \
--header 'Content-Type: application/json' \
--data-raw ${payload}""
We have tried will single quotes for sh and double quotes but nothing works out.
How it can be handled here?
Jenkins doesn't want you to interpolate passwords in the code but rather pass them as environment variables to the shell and let the shell command extract them, that is possible only for parameters that are loaded into the shell execution environment.
In declarative pipelines loading parameters and secrets into shell environment can be done using the environment directive and for scripted pipelines loading secrets can be done via the withCredentials keyword and loading regular parameters can be done via the 'withEnv` keyword.
In your case you have the Token parameter which is loaded into environment by the withCredentials step and the payload parameter which is probably not, so you are mixing two type of parameter contexts, more information on this is available in the Answer for this question.
To solve it you have two options.
The first option is to load the payload into the environment of the shell and use a single quoted groovy string:
withEnv(["PAYLOAD=${payload}"]) {
withCredentials([string(credentialsId: '<SECRETNAME>', variable: 'Token')]) {
sh '''curl --location --request POST "https://abc.example.com/api/endpoint" \
--header "Authorization: Bearer $Token" \
--header "Content-Type: application/json" \
--data-raw $PAYLOAD'''
}
}
Second option is to separate the construction of the string into two types, and handle each section with the relevant method:
withCredentials([string(credentialsId: '<SECRETNAME>', variable: 'Token')]) {
sh '''curl --location --request POST "https://abc.example.com/api/endpoint" \
--header "Authorization: Bearer $Token" \
--header "Content-Type: application/json" \
--data-raw ''' + payload
}
Since last week, the catalog search on Mendeley API is giving me the following result:
{
"message": "Client ID <client_id> is not allowed",
"status": 403
}
I am using standard code in Python that worked before:
mendel = Mendeley(client_id=client_id, client_secret=client_secret)
auth = mendel.start_client_credentials_flow()
session = auth.authenticate()
print(session.catalog.search('Nitrogen dynamics', view='all').list(50).items)
And I have the same result using curl:
curl -X POST \
-H "Content-Type: application/x-www-form-urlencoded" \
-u client_id:client_secret \
-d "grant_type=client_credentials&scope=all" \
https://api.mendeley.com/oauth/token
curl -X GET "https://api.mendeley.com/search/catalog?access_token={access_token}"
Can anyone please help me out. I'm getting error while generating KONG client credentials on HTTP port 8000.
{
"error_description": "You must use HTTPS",
"error": "access_denied"
}
I have added trusted_ips = 0.0.0.0/0,::/0 in kong.conf also, but it didn't work.
You should do it over https(using port 8443 instead of 8000).If youre using localhost Do something like:
curl -X POST \
--url "https://127.0.0.1:8443/<route name>/oauth2/token " \
--header "Host: <route host>" \
--data "grant_type=password" \
--data "client_id=<clientid>" \
--data "client_secret=<clientsecret>" \
--data "provision_key=<provision_key>"\
--data "redirect_uri=http://localhost/cb/" \
--data "authenticated_userid=<userid>" \
--insecure
you can follow this link for further details on how to go about this
Not getting Build job details/status of the PR when using Bitbucket API for any pull request
Here is my API URL:
https://example.com/rest/api/1.0/projects/{projectkey}/repos/{reposlug}/pull-requests/{pullrequestID}
How Build status looks like on GUI:
I also tried below methods to get the Build status but no luck
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/pull-requests
/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/settings/hooks
So I wanted to get whether build status of any PR whether it is Success or Fail
Thanks in Advance for your answers.
The build status is on the commit, not on the PR. First you should find the latest commit of the source branch by calling /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}. see the docs for more details
Once you have the commit id you can query the build-status api by calling /rest/build-status/1.0/commits/{commitId}. See the docs for more details
Using API 2.0
Get statuses: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/pullrequests/%7Bpull_request_id%7D/statuses
Set status: https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories/%7Busername%7D/%7Brepo_slug%7D/commit/%7Bnode%7D/statuses/build
Example:
curl --request GET \
--url https://api.bitbucket.org/2.0/repositories/piavita/com.piavita-vet.ios/pullrequests/300/statuses \
--header 'Authorization: Basic SecretKey' \
--header 'Content-Type: application/json'
curl --request POST \
--url https://api.bitbucket.org/2.0/repositories/piavita/com.piavita-vet.ios/commit/8619291af393/statuses/build \
--header 'Authorization: Basic SecretKey' \
--header 'Connection: keep-alive' \
--data '{\n "url": "http://jenkins.ddns.net:8080/job/jobName/123/",\n "state": "SUCCESSFUL",\n "key": "JENKINS"\n}'