I'm writing a bash script to automatically setup a private github repo, as well as setup a deployHQ project for the same. This works well. However I can not add the GitHub repository to deployhq (via bash script using curl api calls) seemingly because I figure that there hasn't been an initial commit yet.
The idea of the script is to set everything up initially. From GitHub to deployhq to uploading deployhq ssh-rsa keys to the github repository - For each client website we begin to work on.
I'm using API keys, and in particular I'm using a personal access token to send commands to GitHub.
So my question is, how do I setup a new repository on GitHub with an initial commit, before the project has even started? (in order to satisfy deployhq)
I figure I need to use the API key to do this, as to avoid any user prompts.
It could just be a simple README.md file.
This is what I'm using so far (which works).
Note: obviously this is just part of the script.
SETUP_GITHUB_PROJECT_JSON='{
"name": "'$DHQ_PROJECT_PERMALINK'",
"description": "This project is a test",
"private": "true"
}'
SETUP=`curl -X POST -d "$SETUP_GITHUB_PROJECT_JSON" -H "$HEADER_ACCEPT" -H "$HEADER_CONTENT_TYPE" -u $GITHUB_API_KEY:x-oauth-basic "$GITHUB_BASE_URL"user/repos`
Happy to clarify as needed.
Related
I am trying to trigger a pipeline using $CI_JOB_TOKEN. But it gives a 404 error everytime. Is there somebody could block CI_JOB_TOKEN from triggering a pipeline ?? at access levels ??
curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://gitlab.eample.com/api/v4/projects/73237/trigger/pipeline
For me using the CI_JOB_TOKEN also returned a 404 error for a private repository. When I instead executed the same command using a pipeline trigger token (Settings > CI/CD/ Pipeline triggers) it works as expected.
A similar problem is described in this issue https://gitlab.com/gitlab-org/gitlab/-/issues/17511
Just for clarification: You have to generate the token in the other project and then set it as a custom ci variable e.g. PIPELINE_TRIGGER_TOKEN in the project where you want to use it. Then in the curl request within .gitlab-ci.yml replace CI_JOB_TOKEN with PIPELINE_TRIGGER_TOKEN.
Could you please make sure the ref=master is correct? Recently master was changed to main your API call might be hitting a non-existent branch hence 404
Check also your GitLab version:
With GitLab 14.1 (July 2021), you have:
Default branch name redirect
Default branch name redirect
As part of the larger effort to rename Git’s default initial branch in a GitLab project from master to main, we are adding an automatic redirect to streamline the transition. Previously, when projects renamed the default branch, current URLs would result in 404 Not Found. This is a frustrating experience when you are trying to navigate between branches. Now, if you navigate to a file or directory path whose default branch was renamed, you will be redirected to the updated path automatically.
See Documentation and Issue.
So your problem might not exist with 14.1.
Here's what I want to do:
I have a hosted website on a Linux server.
This site is pointed to a GitHub repository.
I want to be able to push changes to the repository, then be able to log into my website and click a button to have the site pull the new code in order to update itself.
Here's how I do it manually:
I created a file on the Linux server called update_site
I log into my Linux server via ssh and type .\update_site which goes to the site's directory and executes a fetch and pull
the first time it asked me to enter my login and password which I did
but since I had set git config --global credential.helper store, it never asks me again
Here's how I want to automate it:
I created a PHP file which executes the file update_site
However, since the PHP website is apparently executing code as another user, it doesn't have my credentials for GitHub
Here's my question:
How can I automate the process so that when the website executes the update_site file, my GitHub login and password are sent as well. And needless to say, how can I do this as securely as possible, i.e. without saving my GitHub password somewhere as plain text?
One possible way to do this automation is to use cron. Edit your cron record (with crontab -e command) and add line like this:
*/5 * * * * /path/to/update_site
In above line 5 mean every 5 minutes
I'm trying to download a raw file from one of my IBM Cloud Git Repos and Issue Tracking repositories. I had a script that was able to fetch raw file contents using the following curl command:
curl -H "Private-Token: $PERSONAL_ACCESS_TOKEN" https://git.ng.bluemix.net/:owner/:repo/raw/:branch/:filename
but it recently started failing with a 302 response that is redirecting to a UI login page.
Is there a supported way to download raw file contents from an IBM Cloud Git Repos and Issue Tracking repository?
The curl request above is attempting to use a personal access token to authenticate to a UI endpoint. There was a security fix in GitLab 11.3.11 that limited the scope of personal access tokens to API calls only. That would explain why personal access tokens are no longer working on that request.
The supported method of downloading raw file contents would be to call the repository files API.
For example, to fetch myFolder/myFile.txt from the master branch of myRepo, owned by myUser, you can make a curl call like this:
curl -H "Private-Token: $PERSONAL_ACCESS_TOKEN" https://git.ng.bluemix.net/api/v4/projects/myUser%2FmyRepo/repository/files/myFolder%2FmyFile.txt/raw?ref=master
Our Gitlab pipeline generates some performance graphs, which I would like to be sent to every team member via e-mail.
So far, they are marked as artifacts so Gitlab keeps them. Is there any way within Gitlab to achive this? Or should I do that within the job script?
There is no way currently to send artifacts via email from the gitlab interface. You will indeed have to send them from your job scripts.
Gitlab can send an email after a pipeline is finished (see in Settings>Integrations>Pipeline emails), but it doesn't attach artifacts.
Another way to share them would be to publish them in gitlab pages from your job script (doc here : https://docs.gitlab.com/ee/user/project/pages/index.html), but it wouldn't send an email.
It seems that a few years down the road nothing has changed yet (or I do not know about it).
send_email:
stage: notify
when: on_failure
script: curl -s --user "api:$MAILGUN_API_KEY"
"https://api.mailgun.net/v3/$MAILGUN_DOMAIN/messages"
-F from='Gitlab <gitlab#example.com>'
-F to=$GITLAB_USER_EMAIL
-F subject='Test results + report'
-F text='Testing some Mailgun awesomeness!'
-F attachment='#reports/report.html'
There are a few things you need to get this to work:
generate an artifact in another job (the file you want to upload; mine is reports/report.html)
define the variables MAILGUN_API_KEY and MAILGUN_DOMAIN
I needed something similar so here is a snippet from my pipeline.
I have also documented everything in a blog post. https://medium.com/#vdespa/send-gitlab-ci-reports-artifacts-via-e-mail-86bc96e66511
I hope this helps a bit.
We have a GITlab(8.14) running for collaboration within the company.
I am working on a python script to collect information about merge requests being raised by developers across projects. I can very easily isolate the merge requests using 'git log'
git log --merges
However, I haven't been able to locate the correct command or option to retrieve all the discussion/comments taking place in the Merge Request.
Solution 1: use Gitlab Log System
Have you thought to use the Gitlab Log System instead of using a Git command?
It contains information about all performed requests.... Also you can see all
SQL request that have been performed and how much time it took.
Please take a look here https://docs.gitlab.com/ee/administration/logs.html
So in your Python script of collecting information, you can use queries like that:
SELECT <things> FROM "merge_requests" WHERE <condition>
Solution 2: use Gitlab API
Another way is to directly request Gitlab API to get a list of all notes for a single merge request.
Notes are comments on snippets, issues or merge requests.
like this:
GET /projects/:id/merge_requests/:merge_request_id/notes
The complete API reference for merge request notes is available here.
Does this help you?