How Do I Query GitLab (issues, milestones, etc) from within a GitLab Pipeline - gitlab

Problem Summary
I am creating my first GitLab pipeline and setting it up to do a release. I would like to add a change log to the published release information. (found in Deployments -> Releases in the GitLab UI).
I would like to, from the pipeline, query the project for something like "closed issues since the date of the last release" and add those tickets to the published release.
Planned Approach
I am successfully using the "release-cli" tool from GitLab to create the release. I followed the example: "Create release metadata in custom script" on this page.
I found the description tag in the release element can be given a .md file, which seemed perfect for posting my change log. I have made a test .md file and added it as the release description and it looks great. It shows up right under "Evidence Collection" and so I planned to do "Change Log" as the header in my .md file. In the above example, GitLab is clearly using an .md file in their description element for extra information such as this.
Where I'm Stuck
I just can't figure out how to query the gitlab project from the pipeline (for issues or whatever).
I have been looking at GitLab's cli project and see likely has all the tools I need. I can not find any examples of using it in a pipeline. I cannot find for sure that its in a docker image that I can use similar to the release-cli tool.
I am stuck. The lack of information makes me wonder if I'm going down a dead end path. Is there anybody that has done something similar that can give me a basic example? Or an alternative?

Related

PhpStorm / WebStorm, Tasks and GitLab Issues

It's easy to setup GitLab issues in PhpStorm or WebStorm (description see here)
But I wonder about some questions in working with it.
Change Status in GitLab
If I open an Issue to work on it (Tools ⇒ Tasks & Content ⇒ Open Task ⇒ choose one from the listed ones), where can I change the Status of this task in GitLab?
I mean something like in Progress, done ...
In a youtube-video - which told how to connect to jira - I've seen something like an Status-Field you can set for the ticket... but I don't found something like this for my GitLab connection?!
Connect Issue with new branch
If I create a new Branch from task, it recommend something like:
#252-my-GitLab-Issue-description (then I push it to gitlab)
But if I open GitLab in my browser, I don't see this new created branch automatically assignd with the related issue. (Shouldn't this be the case?)
Gitlab Issues don't rely on a "status" field like you'd see in other projects. For Gitlab Issues the only status is "open" or "closed". Otherwise, you can use Labels to track your project-specific statuses, and you can use Issue Boards that are based on your Labels to move issues from one status to another.
Here's one of Gitlab's Issue Boards that they use to develop Gitlab itself. Each column in the board is a label on the Issue.
Here's a super-zoomed-out screenshot of that board, with most of the columns collapsed to show an example of what you can do with the Labels and Boards

Azure Devops - YAML Release Pipelines - How to select a specific artefact from a build pipeline using a dropdown list

So, recently I set about migrating our Azure Devops Classic Release pipeline to a YAML based one.
What I'm struggling to reproduce is the ability you have with a Classic Release pipeline to select a specific artefact from an associated build pipeline using a dropdown list.
The only way I've found to allow a user to specify a specific artefact is via a parameter, but the definition of dropdown lists is only possible if you know all of the values that will be in the list.
This link is the closest thing I've found that resolves the issue, but even this doesn't allow the specification of a dropdown: https://www.huuhka.net/runtime-artifact-selection-in-azure-pipelines-yaml/
Anyone know how to do this, or even if it is possible?
Ok, so I didn't quite answer the question I posed, but I found an answer that solves the issue I have.
The problem I had is that I want a user to be able to select a specific build at release time.
This is poorly documented and it was a surprise when I saw it working.
In your release pipeline specify a resource:
resources:
pipelines:
- pipeline: YourBuildPipelineReference
source: "Your Build Pipeline Name"
Now when you come to run your pipeline you see the following:
Click Resources and you are now taken to list where you can select a specific build.
Didn't see this before, but I figure lots of people will need this.

How to change pipeline badge name

As the standard pipeline badge from GitLab looks like this
you can tell pretty well that those are not really distinguishable.
Is there a way to change the pipeline text manually or programmatically to something else for each badge?
Btw, the badges were added with those links
https://gitlab.com/my-group/my-repository/badges/master/pipeline.svg
https://gitlab.com/my-group/my-repository/badges/dev/pipeline.svg
Additional facts:
The pipeline runs locally on my computer
My repo is private
I know it is a bit of an old post, but I was looking for the same and found that it is available now since GitLab 13.1.
The text for a badge can be customized to differentiate between multiple coverage jobs that run in the same pipeline. Customize the badge text and width by adding the key_text=custom_text and key_width=custom_key_width parameters to the URL:
https://gitlab.com/gitlab-org/gitlab/badges/main/coverage.svg?job=karma&key_text=Frontend+Coverage&key_width=130
The example is for the Coverage badge but this also works for Pipelines, so in your case:
https://gitlab.com/my-group/my-repository/badges/master/pipeline.svg?key_text=master&key_width=50
https://gitlab.com/my-group/my-repository/badges/dev/pipeline.svg?key_text=dev&key_width=50
(Found this via https://microfluidics.utoronto.ca/gitlab/help/ci/pipelines/settings.md#custom-badge-text)
There are multiple ways how you can achieve custom pipeline badges in GitLab.
One way could be to use Shields.io which provide a way to generate dynamic badges for your Gitlab repository via a jsonfile.But if your repository is private (only accessible from internal network) then you will get an inaccessible message in your badges.
Otherwise, if your build uses python Docker images or any other python installation with dependencies, you can simply install the anybadge package and generate svg badges to be used in the project from the artifacts directly.
It would be good in future that GitLab offers us more cleaner way to customize the badges, but for now I think those are the workaround solutions.

Gitlab markdown links to artifacts

Is it possible in Gitlab to have source controlled markdown that contains a link to an artifact?
My runner generates metrics that are saved to a file. This output, of course, does not belong in version control. If it was in version control, I could just link to it, no problem. Instead, I mark the output as an artifact so that it is saved after the build is complete.
Currently, our devs can click the [passed] icon for the build that generates the metrics, then click 'Build Artifacts'|'Browse'|dir1|... down to the generated output metric. This is complicated, and you have to know exactly where to look.
It would be way more convenient to have a link to the artifact in the README.md.
These docs say that I can choose to store my artifacts in a different location, but that seems like a heavy solution, and it does not generalize to artifacts from different projects.
These docs say that I can embed build numbers in the artifact filename, but that's not really what I'm after. I just want the artifacts from the most recent build.
What I want is a persistent URL for the artifact, but I am unable to find anything of this nature.
Update February 2018:
Since Gitlab 8.12, the link is https://gitlabInstance/myNamespace/repository/master/archive.zip. (e.g: https://gitlab.com/rpadovani/my-gitlab-ci/repository/master/archive.zip).
There are also other formats.
You can see all the formats clicking on the little cloud in the top right of the homepage of your project.
ORIGINAL ANSWER
They are working on it right now.
Since GitLab 8.10, there is an API to do that:
curl -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/builds/artifacts/master/download?job=test"
Unfortunately you still cannot use the web interface, but there is already a MR to implement it (and a related bug with discussion).
After that MR you can link the build in your README

Is there a way to add coverage report to gitlab?

I understand that gitlab has support to Jenkins CI, but what I need is a lot less than that.
I have a Rails application and get the coverage from the tests using simplecov. It generates HTML output in a directory by running a rake task. I would like to see the current coverage through gitlab. Is there a simple way to integrate this report with gitlab?
I fear there is still no easy way to integrate code coverage reports but Gitlab now supports (since Version 8.0 integrated) build jobs for your code. Unfortunately you have to implement your solution by writing a custom .gitlab-ci.yml to run your coverage tests. For viewing the reports, you can specify the generated "artifacts" or publish them on gitlab pages.
For more information, see here: https://about.gitlab.com/gitlab-ci/
Additionally you can parse a text output to display a short code coverage report:
(Enable builds and output test coverage)
Go to "Project Settings" -> Builds
Add to "Test coverage parsing" a regular expression (examples below, simplecov included)
See Publish Code Coverage Report with GitLab Pages
The short answer: Unfortunately there is no easy way to do this.
The longer answer:
GitLab not yet has a Jenkins support.
What you basically need is a service like GitLab CI or Jenkins CI, which starts simplecov and posts the output back to GitLab. Unfortunately GitLab does not offer such a functionality yet.
But I know other organizations which do have a Jenkins service for GitLab which automatically comment git pushes with the Jenkins result.
You now (June 2020, GitLab 13.1) have code coverage history, in addition of Test coverage parsing.
Graph code coverage changes over time for a project
All too often, a project has a code coverage target but development teams might not have much visibility into which direction that target value is trending over time.
There needs to be an easier way to track changes in code coverage over time without that extra hassle.
The Code Coverage graph now provides better visibility into how code coverage is trending over time.
It displays a simple graph of the coverage value(s) calculated in pipelines.
See Documentation and Issue
With GitLab 13.6 (November 2020), you also have (not for free though)
Display code coverage data for selected projects
In 13.4, we released the first iteration of Code Coverage data for Groups that enables you to compare the coverage of multiple projects and download the data in a single file from a single screen. However, to analyze the data, you had to open the file to check it manually, and probably imported it into a spreadsheet for further analysis.
In GitLab 13.6, you can now select specific projects in a group to see their latest coverage values directly in GitLab itself without needing to download a file or waste development time accessing code coverage data. We welcome feedback on the functionality and possible iterations for this feature in our feedback issue.
See Documentation and Issue.

Resources