Can I use Gitlab Personal token in Jenkins Global Pipeline Libraries? - jenkins

I want to use Gitlab personal token in Jenkins Global Pipeline Libraries.
When I add a global gitlab api token kind, it is not visiable at credentials meum
What should I do?
My jenkins version is 2.319.3, git plugin version is 4.11.5

Related

how to retrieve git build data from jenkins pipeline

I'm trying to retrieve the Git Build Data from jenkins pipeline and sent the details by mail
Is there any API or inbuilt variable available?
You can use GitLab APIs for this. Also, check Gitlab CLI as well.

Jenkins install default plugins after skipping during installation

I had to skip past the default plugin install page to configure proxy and to fix an issue. But now I need to install default plugins. Is there a way restart the default plugin installation page without having to delete Jenkins container? Or is there a list of default plugin names somewhere where I can manually install.
Here's a list with all of the default plugins, suggested for Jenkins version 2.60.3:
Folders
OWASP Markup Formatter
Structs
Pipeline: Step API
Token Macro
Build Timeout
Credentials
Trilead API
SSH Credentials
Plain Credentials
Credentials Binding
SCM API
Pipeline: API
Timestamper
Script Security
JUnit
Matrix Project
Resource Disposer
Workspace Cleanup
Ant
Pipeline: Supporting APIs
Durable Task
Pipeline: Nodes and Processes
Pipeline: SCM Step
Pipeline: Groovy
Pipeline: Job
Display URL API
Mailer
Pipeline: Basic Steps
Gradle
Pipeline: Milestone Step
Snakeyaml API
Jackson 2 API
Pipeline: Input Step
Pipeline: Stage Step
Pipeline Graph Analysis
Pipeline: REST API
Pipeline: Stage View
Pipeline: Build Step
Pipeline: Model API
Pipeline: Declarative Extension Points API
JSch dependency
Git client
GIT server
Pipeline: Shared Groovy Libraries
Branch API
Pipeline: Multibranch
Pipeline: Stage Tags Metadata
Pipeline: Declarative
Lockable Resources
Pipeline
OkHttp
GitHub API
Git
GitHub
GitHub Branch Source
Pipeline: GitHub Groovy Libraries
Subversion
SSH Build Agents
Matrix Authorization Strategy
PAM Authentication
LDAP
Email Extension
seems like, better to re-install jenkins

Handing Secrets in Jenkins pipeline

I'm new to Jenkins world, I have a usecase where I have setup a jenkins pipeline using JenkinsFile. As part of deployment stage, we will invoke a few ansible script in the backend to get the image deployed into Kubernetes cluster running in cloud environment. The script expects few secrets in environment variable, so I like to understand which is the best option to handle secret in Jenkins, do I need them to enter into jenkins credentials and read them in jenkins environment tag like below. Or It is safe to get the value from the user using input plugin when executing the pipeline, but if I get from user then I would not able to completely automate pipeline will wait until user input the secret. Could you help in safe way to handle credentials.
pipeline{
agent any {
environment {
SECRET_VALUE=credentials('SECRET_VALUE_FROM_JENKINS_CREDENTIALS')
}
}
}
It depends on your use case, Indeed both approaches as you mentioned above will work.
There shouldn't be any problem in keeping your secrets as Jenkins credentials, in my case, all my secrets are in the Hashicorp vault and my Jenkins credentials point to the vault location as an example...
- usernamePassword:
scope: GLOBAL
id: serviceUser
username: svc_admin
password: "${secret/xyz/service_user/password}"
description: My secret service user
The Jenkins deployment is via JCasC.
As jenkins admin I can say it is safe to store credentials in jenkins.
Just create credentials in jenkins and use in a pipeline. Also it's nice to have mask password plugin installed in jenkins, which will mask credentials in jenkins jobs' output.

How can I pass Gitlab token stored on Jenkins to pipeline script?

I'm a Jenkins user. Jenkins server has a Gitlab token. How can I pass this token to a pipeline script (Jenkinsfile) so I can use Gitlab API v4.

global tool configurations in jenkins through cli?

Is there a way to add global tool configurations for artifactory and aws in jenkins through cli?
I'm trying to write chef cookbook for automating creation of Jenkins job, but I don't know how to add credentials for tools.
Credentials don't depend on the tools which will use them.
You can register credentials in general through the JENKINS Credentials Plugin API: see for instance
How to create jenkins credentials via the REST API? (similar to jenkins_api_client issue 162)
update Jenkins credentials by script
You can then use those credentials in association with a Jenkins Job.
Your question is twofold.
Credentials
The Jenkins chef cookbook offers a jenkins_credentials resource, which allows you to pipe credentials (using Jenkins API internally) into your Jenkins instance.
Global Tool Configuration
You can use the jenkins_script resource of the same cookbook to execute any Groovy script. This allows you to configure your Jenkins instance. You now just have to figure out exactly, what the code is to, e.g., select the previously defined credentials. But the code looks similarly to the example given in the cookbook's README.

Resources