Github actions temporary variable cant be interpreted - variables

in my Github action I use a temporary variable for a timestamp and want to send this variable in a webhook, but github cant interpret the $var in string. Can someone pls help me?
The code looks like this:
- name: Posting Rocketchat
if: failure()
run: |
TS=$(date +%Y%m%d%H%M%S)
curl -X POST -H 'Content-Type: application/json' --data '{"text":"❌ Test: Leads Testing Desktop 💻","image_url":"https://myurl.net/$TS-1.png"}' https://chat.myurl.com/hooks/yxyxyxxyxyxyx/xxxxxyxyxyxyxyxyxy

Use instead
- name: Posting Rocketchat
if: failure()
run: |
echo "TS=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV
curl -X POST -H 'Content-Type: application/json' --data '{"text":"❌ Test: Leads Testing Desktop 💻","image_url":"https://myurl.net/${{ env.TS }}-1.png"}' https://chat.myurl.com/hooks/yxyxyxxyxyxyx/xxxxxyxyxyxyxyxyxy

Related

invalid_payload while passing variable in slack POST CURL command in gitlab.ci.yml

I am keep on getting invalid_payload and not able to trigger email to Slack channel.
send_email:
stage:notify
when:always
variables:
PASSED_COUNT: "'{\"passed\":1}'"
DEPLOY_CURL_COMMAND: 'curl -X POST -H "Content-type:application/json" --data $PASSED_COUNT https://hooks.slack.com/services/xxxxx/xxxxxxx/..'
script:
- echo "Testing Platform"
- echo $DEPLOY_CURL_COMMAND
- 'eval "$DEPLOY_CURL_COMMAND"'
- curl -X POST -H 'Content-type:application/json' --data '{"text":"'$PASSED_COUNT'"}' https://hooks.slack.com/services/xxxxx/xxxxxxx/..'

Apicurio registry - Documentation tab for artifact is empty

When I upload artifact to the ApiCurio registry using UI it works fine but if I use CURL for the same artifact, Documentation tab is empty. Any ideas?
I use:
curl -X POST -H "Content-type: application/json" -H "X-Registry-ArtifactType: OPENAPI" -H "X-Registry-ArtifactId: test" --data "{$body}" http://registry:8080/api/artifacts
should use "$body" instead of "{$body}"

GitLab CI variables in job api?

I am using rest API to run manual jobs in GitLab CI. When i start a manual job from UI I am able to define custom variables that i can use during the job. How can i define them when running job through API?
Could not find any documentation on it. Or not even a single question in forums.
This is how i currently run my job
curl -k --request POST --header "PRIVATE-TOKEN: abc" https://mygit.com/api/v4/projects/17/jobs/1956/play
I tried adding:
--form variables[TEST]=hello
But this didnt work.
Edit:
A bit more information on what im doing. So my pipeline has two stages. Build and deploy. On each commit I want build to run once and then i want to be able to deploy this result to multiple different servers. Because the server list is dynamic and there are a lot of them I want to have the IP address of the server as an variable I can give to my deploy job.
Instead of starting a job you can start a pipeline and set the variables from there. Here's an example of how to do this from the GitLab documentation:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{ "ref": "master", "variables": [ {"key": "VAR1", "value": "hello"}, {"key": "VAR2", "value": "world"} ] }' \
"https://gitlab.example.com/api/v4/projects/169/pipeline"
This is the way how I'm using it, didn't find a way to use API tokens for it though.
curl -X POST \
-F token=xxxxxxxxxxxxxxxx \
-F "ref=some_branch" \
-F "variables[VAR1]=abc" \
-F "variables[VAR2]=cde" \
"https://example.gitlab.com/api/v4/projects/312/trigger/pipeline"
Where -F "variables[VAR1]=abc" for example is set in .gitlab-ci.yml.
only:
variables:
- $VAR1
The idea was to create some manual CI jobs and tell the devs they can run them via API call, but since I can only use the project token here, it's absolutely not secure.
It would be really handy to run it via
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>"
Passing variables is documented in gitlab-org/gitlab issue 2772, but more about triggering pipeline (not job)
See if that syntax would work, for trigger variables (syntax variables[xxx]=yyy):
# gitlab-ci.yml
build:
script:
- curl --request POST --form "variables[PRE_CI_PIPELINE_SOURCE]=$CI_PIPELINE_SOURCE" --form "token=$CI_JOB_TOKEN" --form ref=master http://192.168.10.3:3001/api/v4/projects/13/trigger/pipeline
Or simply for regular variables --form key=value:
curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://gitlab.example.com/api/v4/projects/9/trigger/pipeline
It looks like that as of Jan 25, 2021 this feature not yet supported. There is a feature request I found here: https://gitlab.com/gitlab-org/gitlab/-/issues/37267
Update 2022-03:
After you create a trigger token, and create trigger_pipeline step in pipeline, like this
trigger_pipeline:
tags:
image: alpine:latest
stage: deploy
script:
only:
variables:
- $MANUAL
you can use it to trigger pipelines with a tool that can access the API
curl --request POST \
--form token=TOKEN \
--form ref=main \
--form "variables[MANUAL]=true" \
"https://gitlab.example.com/api/v4/projects/123456/trigger/pipeline"
or a webhook:
https://gitlab.example.com/api/v4/projects/123456/ref/<ref_name>/trigger/pipeline?token=<token>
for example for manual run.

AWS error when trying to publish an Autodesk Forge Design Automation App bundle

When following the steps described here: https://forge.autodesk.com/en/docs/design-automation/v3/tutorials/revit/step4-publish-appbundle/#step-3-upload-the-appbundle I get an Aws specific error.
<Error><Code>AccessDenied</Code><Message>No AWSAccessKey was presented.</Message>
I have verified my request but it seems that both the header and all form data has been set correctly, as described in this example:
curl -X POST \
https://dasprod-store.s3.amazonaws.com \
-H 'Cache-Control: no-cache' \
-F key=apps/Revit/DeleteWallsApp/1 \
-F content-type=application/octet-stream \
-F policy=eyJleHBpcmF0aW9uIjoiMjAxOC... (truncated) \
-F success_action_status=200 \
-F success_action_redirect= \
-F x-amz-signature=6c68268e23ecb8452... (truncated) \
-F x-amz-credential=ASIAQ2W... (truncated) \
-F x-amz-algorithm=AWS4-HMAC-SHA256 \
-F x-amz-date=20180810... (truncated) \
-F x-amz-server-side-encryption=AES256 \
-F 'x-amz-security-token=FQoGZXIvYXdzEPj//////////wEaDHavu... (truncated)' \
-F 'file=#path/to/your/app/zip'
Of course, all values have been replaced with the response received from
curl -X POST \
https://developer.api.autodesk.com/da/us-east/v3/appbundles \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"id": "DeleteWallsApp",
"engine": "Autodesk.Revit+2018",
"description": "Delete Walls AppBundle based on Revit 2018"
}'
Now, since this is an AWS specific error, maybe there have been some changes to the AWS api and are the examples given in the forge documentation not up to date?
This seemed to be a client issue.
I am using the request npm package in node.js and did set the formData as part of the form attribute, instead of the formData attribute.
const request = require('request-promise');
return request.post(uploadParameters.endpointURL, {
headers: {
'Content-Type': 'multipart/form-data',
'Cache-Control': 'no-cache'
},
formData: { // use formData instead of form
...uploadParameters.formData,
file: fs.createReadStream(EXPECTED_APPBUNDLE_PATH)
}
})
Glad you figured out what was going on :)
If you want a nodejs sample/example for Design Automation, you can take a look at this repository. Even tough it has been built for 3ds Max, the Design Automation concepts are still the same.
https://github.com/Autodesk-Forge/design.automation.3dsmax-nodejs-basic/blob/master/createAndUploadApp.js
Hopefully, something in there can be useful to you.

How to use markdown for description from a file in gitlab CI using release API

I'm using the Gitlab release API in the gitlab-ci.yml to be able to automatically create a new release when deploying.
Simply putting a curl request like here in the docs works just fine. For the description, the docs state that markdown is allowed, which is great. However, I can't seem to figure out or come up with an idea to load a description from a markdown file within the curl request. I've already tried storing the content of the markdown file in a variable in the gitlab-ci.yml prior to the curl and then pass it and expand it within the curl like so:
# gitlab-ci.yml
...
- DESCRIPTION=`cat ./description.md`
and also to just put the cat ./description.md in the curl request itself as the value of "description".
Here is the example from the docs:
curl --header 'Content-Type: application/json' --header "PRIVATE-TOKEN: gDybLx3yrUK_HLp3qPjS" \
--data '{ "name": "New release", "tag_name": "v0.3", "description": "Super nice release", "milestones": ["v1.0", "v1.0-rc"], "assets": { "links": [{ "name": "hoge", "url": "https://google.com" }] } }' \
--request POST https://gitlab.example.com/api/v4/projects/24/releases
And for the "description" key I would like to pass the contents of a markdown file as the value.
I was surprised to not have found a post or discussion about this already, so I suspect I'm either missing something (very basic/obvious) or folks don't really use this function (yet)?
Any help will be much appreciated.
Using the variable like you, this .gitlab-ci.yml works :
create_release:
script:
- DESCRIPTION=$(cat description.md)
- |
curl --silent --request POST --header "Content-Type:application/json" \
--header "PRIVATE-TOKEN: TOKEN" \
--data '{"name":"New release","tag_name":"v0.3", "description":"'"$DESCRIPTION"'","assets":{"links":[{"name":"hoge","url":"https://google.com"}]}}' \
https://gitlab.bankassembly.com/api/v4/projects/369/releases
The variable is expanded inside double quote (see https://superuser.com/a/835589)
Example of the content of my description.md :
## CHANGELOG\r\n\r\n- Escape label and milestone titles to prevent XSS in GFM autocomplete. !2740\r\n- Prevent private snippets from being embeddable.\r\n- Add subresources removal to member destroy service.