Is it possible to search for pipeline by execution date?
Example, I need to fine results of pipelines that was executed at 2023-01-31.
I have look around of net, but could not find any suggestion how to do this.
I do not know a GUI way, but you can use GitLab Pipelines API to search and filter pipelines programmatically.
Use updated_after or/and updated_before fields when requesting GET /projects/:id/pipelines API endpoint. Example from documentation without filtering:
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/pipelines"
For full accepted parameters reference please follow the official documentation: List project pipelines.
Related
What I want
I have a python backend application, using a service account, running in docker.
I have a cloud build trigger that is connected to a bitbucket repository. This trigger uses a webhook. For revision I use tags.
I want to trigger this webhook with my backend application. I want to provide a specific tag (using a placeholder variable).
I want the backend to give me a list of all available tags (like I get on the console.google.com frontend, see screenshot)
What I tried
I tried this API endpoint using a Bearer token (which works fine), but it doesn't provide me with a tag list: Source Repo API
curl https://sourcerepo.googleapis.com/v1/projects/<project>/repos/<repo>' --header "Authorization: Bearer $(gcloud auth print-access-token)" --header 'Accept: application/json'
Because it is possible to retrieve all tags in the cloud console, I used the developer tools to find the endpoint that provides me with all available tags:
https://console.cloud.google.com/m/source/repos/get?project=<project>&repo=<repo>
My issue here is that it takes cookies to authenticate, if I use the Bearer token it does not work.
Is it possible to authenticate my service account automatically against console.google.com to use this endpoint? Or is there another way to get a list of tags?
From what you have explained I understand that your concerns are:
1. If there is a way to get the list of tags from your repository that you are able to see in the GCP console using the endpoint that you have found.
The information that the console displays regarding tags do not come from any REST or gRPC API (the APIs provided by Google), but rather it comes directly from the git API. The console frontend runs a command similar to git tag in order to get the tags from your repository. The tags are not stored within the GCP system, the console only queries the git repo for the tags.
2. Can I authenticate with a service account on the console?
No. The APIs used by the web frontends (i.e. APIs starting with https://console.cloud.google.com) will only allow cookie authentication, which only user accounts can obtain. There is usually a way to translate a frontend API (https://console.cloud.google.com) to a GCP API (https://*.googleapis.com), where you can use regular authentication to retrieve the information. However,in this case, the tag information is not in a GCP API (but rather inside the git repo), so there is no translation available.
3. If there is another way to list the possible tags present in the repository?
I tried to reproduce your situation to find a way to be able to get the list of the tags present in one repository, in this case a Bitbucket repository, and I found that you will be able to get this data using the $ git tag command. In this documentation you will be able to find all the commands related to Repository tags.
Knowing this, after linking the Bitbucket Repository to my code, I was able to get the list of tags after using the $ git tag command.
I want to change the context of file and commit by using gitlab api. I looked the api documentation and couldn't find a way to do it.
The documentation link is here;
https://docs.gitlab.com/ee/api/
Is it possible to do change the file and commit it? Do you have any example?
Here is the official documentation for updating a file via the api: https://docs.gitlab.com/ee/api/repository_files.html#update-existing-file-in-repository
Example:
curl --request PUT --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' 'https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb?branch=master&author_email=author%40example.com&author_name=Firstname%20Lastname&content=some%20other%20content&commit_message=update%20file'
Related question: Updating and committing file by using gitlab api
You should use git for this use case, not the API which is not designed for this!
I want to automate building and deploying of projects. In this regard, I want to use GItlab API to retry particular jobs in Gitlab Pipeline.
The API call I make as follows:
curl --request POST --header "PRIVATE-TOKEN: xxx" "https://gitlab.example.com/api/v4/projects/1/jobs/1/retry"
My Job otherwise can be triggered manually and my gitlab-ci.yml file looks like this:
execute_octoDeploy:
tags:
- windows
stage: build
when: manual
script:
- .\BuildScripts\octodeploy.ps1
I get 403 error, which according to https://docs.gitlab.com/ee/api/README.html means that I am not authorized.
Whereas I have all the rights of the project and I am the owner of the same.
To add:
I can trigger other non-manual jobs but not this.
I also referred:
https://gitlab.com/gitlab-org/gitlab-ce/issues/22824
What might be wrong? How can I solve this?
I seem to have found the solution for this:
You need to add scope of the jobs in the API call
Also Retry method will work only when you have canceled your job in that pipeline.
You can try:
curl --header "PRIVATE-TOKEN: xxxxx" 'https://gitlab.example.com/api/v4/projects/1/jobs?scope[]=pending&scope[]=running'
and then specify if you want to play/retry a job.
I would like to know if there is a way to get the languages (percentage per language) used in a project by using the API provided by GitLab. I checked their documentation but I didn't see anything about that or maybe I missed it.
I know that they use the Linguist library but I'm developping an application that's is not in Ruby and I'm looking for a way to integrate theses percentages.
As of 10.8.x, Gitlab added a new API entrypoint, exposing languages used in a specific repository.
Usage is straight forward :
curl --header "PRIVATE-TOKEN: <__ACCESS_TOKEN__>" https://gitlab.mydomain.com/api/v4/projects/<ID>/languages
docs : https://docs.gitlab.com/ee/api/projects.html#languages
Hope this helps!
Looks like there's no endpoint to do this right now as the data for language repartition is sent in inline javascript. But it might become available as they refactor the code (see this and this)
How do I filter the results of the following command to only give me the pull requests with a certain label: "Ready To Release" with the github api?
curl -u <token>-oauth-basic https://api.github.com/repos/<reponame>/<branch>/pulls
Found the answer in the Github Api
Just go to the following url and it will return the labels that the pull request is tagged with:
https://api.github.com/repos/{organization_name}/{repo}/issues/{pull_request_number}/labels?access_token='{github_token})