Postman api key not valid in gitlab-ci - gitlab

In my gitbal-ci.yml using the below instruction:
curl -s https://api.getpostman.com/environments?apikey=${POSTMAN_APIKEY}
I receive the error:
error: could not load environment
Invalid API Key. Every request requires a valid API Key to be sent.
The variable POSTMAN_APIKEY is correctly set in my gitlab Setting CI/CD as POSTMAN_API with the key generated in my postman account.
If I try to execute the curl command via shell, it works perfectly.
What's wrong? thanks

I think you should use double quotes "curl -s https://api.getpostman.com/environments?apikey=${POSTMAN_APIKEY}" because of variable expansion in bash. But variable name must be the same in Setting CI/CD, so POSTMAN_APIKEY in both places. If you set variable as protected, be sure to flag your branch as protected as well.

Related

Updating a file for a quick-pull using github cli

Currently in the github UI, a user can edit a file and create a new branch in a single action. This can also be done through the github api using something like this:
curl 'https://github.com/<my_org>/<my_repo>/tree-save/master/<path_to_file>' \
-H 'content-type: application/x-www-form-urlencoded' \
--data-raw 'authenticity_token=<generated_token>&filename=<filename>&new_filename=<filename>&content_changed=true&value=<new_contents_of_file>&message=Updated+file+in+my+repo&placeholder_message=Update+<filename>&description=&commit-choice=quick-pull&target_branch=<new_branch_name>&quick_pull=master&guidance_task=&commit=<target_commit_checksum>&same_repo=1&pr='
What I would like to be able to do, is perform the same action using the github cli* (gh). I have tried using the following commands:
gh api <my_org>/<my_repo>/tree-save/master/<path_to_file> -F "filename=<filename>" -F ...
and
gh api repos/<my_org>/<my_repo>/contents/<path_to_file> -F "filename=<filename>" -F ...
For both cases (and many variations on these options), I'm getting a 404** back. Any ideas what I'm doing wrong? Does the github cli even allow the functionality allowed in the above curl?
* For those curious, I want to use the CLI because of how it handles auth and it's statelessness. I can't generate a token to use, like in the curl above. And, due to multiple issues, I also can't clone the repo locally.
** I'm able to retrieve the file just fine using the simple GET command (the second command above without the '-F' flags)
After reading documentation, and then verifying by altering credentials, it appears to be a permissions issue. Evidently, for security reasons, if a token is used that does not meet the required permissions, a 404 is returned instead of a 403.
Interesting that I can still use the curl above through the browser. So, now i need to figure out why the gh cli token does not have the same permissions as my user.

Azure DevOps pipeline not recognizing pipeline variable in Bash script (not using a YAML file)

The Azure DevOps pipeline has this variable:
Name: pat
Value: Git repo authentication token
The pipeline has a Bash script task. It is set to filepath. Filepath is set to script.sh. script.sh begins with:
git clone https://username:$(PAT)#dev.azure.com/company/project/_git/repo-name
Errors in pipeline logs:
PAT: command not found
Cloning into 'repo-name'...
fatal: Authentication failed for 'https://dev.azure.com/healthcatalyst/CAP/_git/docs-template/'
To validate that the authentication token and repo URL are accurate, I can verify this works when run as inline code:
git clone https://username:$(pat)#dev.azure.com/company/project/_git/repo-name
script.sh file is in repo-name.
However, environment variables work. Both of the following return the accurate value within the script. Note that one has no quotes and the other does.
echo $BUILD_REPOSITORY_NAME
repo-name
echo "$BUILD_REPOSITORY_NAME"
repo-name
Based on documentation I've seen (I am having difficulty with Microsoft's docs because I am not using a YAML file), I've tried unsuccessfully:
$pat
$PAT
$(PAT)
"$(PAT)"
gitToken=<backtick - Markdown is not allowing me to show a backtick here>echo $PAT<backtick>
Does anyone know what I'm doing wrong? Thank you for any tips.
Is your PAT variable a secret variable ?
If so, then it's not directly accessible in script files
As you can see in the documentation: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#secret-variables
Unlike a normal variable, they are not automatically decrypted into environment variables for scripts. You need to explicitly map secret variables.
Example:
...
env:
MY_MAPPED_ENV_VAR: $(mySecret) # the recommended way to map to an env variable
Or if you are using the visual editor, like that:
Use System.AccessToken instead of personal PAT:
git clone https://$SYSTEM_ACCESSTOKEN#dev.azure.com/company/project/_git/repo-name
To enable $SYSTEM_ACCESSTOKEN: go to release page in ADO > Tasks > Agent job > check Allow scripts to access the OAuth token

Add GIT_CONFIG in CMake FetchContent_Declare fails on Linux

I'm trying to set http.extraheader to get credentials into a Azure Devops pipeline, by setting http.extraheader="AUTHORIZATION: bearer $ENV{System_AccessToken}". Consider the following snippet:
# For CI we need to set the AUTHORIZATION for git clones
if(DEFINED ENV{System_AccessToken})
set(GIT_CONFIG_EXTRA_HEADER "AUTHORIZATION: bearer $ENV{System_AccessToken}" CACHE STRING "")
endif()
# Fetch the toolbox
include(FetchContent)
FetchContent_Declare(toolbox
GIT_REPOSITORY https://repo/toolbox
GIT_CONFIG http.extraheader=${GIT_CONFIG_EXTRA_HEADER}
)
This works on Windows, but on Linux I get the following error:
[1/9] Creating directories for 'toolbox-populate'
[1/9] Performing download step (git clone) for 'toolbox-populate'
Cloning into 'toolbox-src'...
error: key does not contain a section: AUTHORIZATION:
fatal: unable to write parameters to config file
So, in essence the string in ${GIT_CONFIG_EXTRA_HEADER} is not quoted correctly I guess, but I cannot figure out what to do.
Looks like a bug in CMake. I filed an issue.

Ansible Azure Creds

I am trying to provision infrastructure on Azure Public and Azure Stack. In order to do that I have stored credentials in $HOME/.azure/credentials file as advised by official documentation for Ansible. The configuration looks like this:
[default]
subscription_id=xxx`enter code here`xxx
client=xxxxx`enter code here`
secret=xxxx`enter code here`x
tenant=xxxxx`enter code here`x
[azurestack]
subscription_id=`enter code here`xxxxxx
client=xxxx`enter code here`x
secret=xxxxx`enter code here`
tenant=xxxxxx`enter code here`
cloud_environemnt=`enter code here`x
I tried to execute the playbook as follows:
sudo ansible-playbook -vvv foo.yml --profile=azurestack
It does not work for Azure stack. It says the operation called --profile. Can anyone guide me how to solve the problem?
In the same Ansible documentation, they explain how to do it:
It is possible to store multiple sets of credentials within the credentials file by creating multiple sections. Each section is considered a profile. The modules look for the [default] profile automatically. Define AZURE_PROFILE in the environment or pass a profile parameter to specify a specific profile.
So there is two way, the first one, export first the env variable:
sudo AZURE_PROFILE=azurestack ansible-playbook -vvv foo.yml
And I have to agree that the second way is not that explicit,… I would try by using extra-vars:
sudo ansible-playbook -vvv foo.yml --extra-vars "profile=azurestack"
But not sure at all that this second is correct, and I'm not able to try it.

perforce web client throws error "P4CHARSET must be set in order to connect to a unicode server"

I use perforce as sourcesafe, my desktop client is working fine.
I just install P4Web, perforce web client and when I try to open a file I get the following error:
P4CHARSET must be set in order to connect to a unicode server
I already add P4CHARSET registry key set to utf8 under
HKEY_CURRENT_USER\Software\perforce\environment
What more can I do?
Thanks!
You probably need to set it for the P4Web service. Check out this KB article:
http://kb.perforce.com/article/231/p4web-as-a-windows-service
There are examples of setting other parameters like the port number; you can follow those guidelines for setting P4CHARSET.
you need to run the following line on cmd:
p4 set -S "Perforce Web" P4CHARSET=utf8

Resources