Jenkins Pipeline 流水线 - withCredentials 使用
添加凭证


Pipeline script
pipeline {
agent any
stages {
stage('withCredentials 使用凭证') {
steps {
withCredentials([usernamePassword(credentialsId: 'DockerServer', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
// available as an env variable, but will be masked if you try to print it out any which way
// note: single quotes prevent Groovy interpolation; expansion is by Bourne Shell, which is what you want
bat 'echo ${USERNAME}' //Linux 下 sh 'echo $USERNAME',TODO Windows 上怎么写,
// also available as a Groovy variable
echo USERNAME
// or inside double quotes for string interpolation
echo "username is $USERNAME"
}
echo 'Credentials SUCCESS'
}
}
//指定 Docker 服务器节点。用于编译、上传镜像,指定K8S节点,用于升级程序
stage('指定节点中使用凭证') {
agent { label 'DockerAgent' }
steps {
withCredentials([usernamePassword(credentialsId: 'DockerServer', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh 'docker --version'
sh "echo 'docker login -u ${USERNAME} -p ${PASSWORD} image_url'"
}
echo 'Credentials SUCCESS'
}
}
}
}
执行结果
Started by user admin
[Pipeline] Start of Pipeline (hide)
[Pipeline] node
Running on Jenkins in D:\ProgramData\Jenkins\.jenkins\workspace\PipelineDemo
[Pipeline] {
[Pipeline] stage
[Pipeline] { (withCredentials 使用凭证)
[Pipeline] withCredentials
Masking supported pattern matches of %PASSWORD%
[Pipeline] {
[Pipeline] bat
D:\ProgramData\Jenkins\.jenkins\workspace\PipelineDemo>echo $PASSWORD
$PASSWORD
[Pipeline] echo
root
[Pipeline] echo
username is root
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] echo
Credentials SUCCESS
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (指定节点中使用凭证)
[Pipeline] node
Running on DockerAgent in /opt/jenkins/workspace/PipelineDemo
[Pipeline] {
[Pipeline] withCredentials
Masking supported pattern matches of $PASSWORD
[Pipeline] {
[Pipeline] sh
+ docker --version
Docker version 20.10.18, build b40c2f6
[Pipeline] sh
Warning: A secret was passed to "sh" using Groovy String interpolation, which is insecure.
Affected argument(s) used the following variable(s): [PASSWORD]
See https://jenkins.io/redirect/groovy-string-interpolation for details.
+ echo 'docker login -u root -p **** image_url'
docker login -u root -p **** image_url
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] echo
Credentials SUCCESS
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
Jenkins Pipeline 流水线 - withCredentials 使用的更多相关文章
- Kubernetes DevOps: Jenkins Pipeline (流水线)
要实现在 Jenkins 中的构建工作,可以有多种方式,我们这里采用比较常用的 Pipeline 这种方式.Pipeline,简单来说,就是一套运行在 Jenkins 上的工作流框架,将原来独立运行于 ...
- jenkins pipeline 流水线生产
jenkins pipeline : pipeline { agent any parameters { string(name: 'git_version', defaultValue: 'v1.1 ...
- 使用Jenkins pipeline流水线构建docker镜像和发布
新建一个pipeline job 选择Pipeline任务,然后进入配置页面. 对于Pipeline, Definition选择 "Pipeline script from SCM" ...
- Jfrog Maven jenkins pipeline 流水线 培训 简单实验
1. 公司购买了一套jfrog artifactory ,然后厂商组织了一次培训 本次简单记录一下 jenkins和jfrog 二进制仓库的简单连接使用 2. 前期环境准备. scp jdk的tar包 ...
- 基于Jenkins Pipeline的ASP.NET Core持续集成实践
最近在公司实践持续集成,使用到了Jenkins的Pipeline来提高团队基于ASP.NET Core API服务的集成与部署效率,因此这里总结一下. 一.关于持续集成与Jenkins Pipelin ...
- Jenkins + Pipeline 构建流水线发布
Jenkins + Pipeline 构建流水线发布 利用Jenkins的Pipeline配置发布流水线 参考: https://jenkins.io/doc/pipeline/tour/depl ...
- jenkins的流水线pipeline+项目实验php
声明:实验环境使用Jenkins的应用与搭建的环境 新建一个流水线 pipeline脚本语法架构 node('slave节点名'){ def 变量 #def可以进行变量声明 stage('阶段名A') ...
- 有手就行5——jenkins项目构建类型(pipeline流水线项目构建推荐)
有手就行5--jenkins项目构建类型(pipeline流水线项目构建推荐) Pipeline简介 1) 概念 Pipeline,简单来说,就是一套运行在 Jenkins 上的工作流框架,将原来独立 ...
- Pipeline流水线设计的最佳实践
谈到到DevOps,持续交付流水线是绕不开的一个话题,相对于其他实践,通过流水线来实现快速高质量的交付价值是相对能快速见效的,特别对于开发测试人员,能够获得实实在在的收益.很多文章介绍流水线,不管是j ...
- Jenkins pipeline:pipeline 使用之语法详解
一.引言 Jenkins 2.0的到来,pipline进入了视野,jenkins2.0的核心特性. 也是最适合持续交付的feature. 简单的来说,就是把Jenkins1.0版本中,Project中 ...
随机推荐
- 基于.net6.0 Fast.ORM 已全面支持AOT编译 所有Api均测试通过
Fast Framework 作者 Mr-zhong 代码改变世界.... 一.前言 Fast Framework 基于NET6.0 封装的轻量级 ORM 框架 支持多种数据库 SqlServer O ...
- 【Javaweb】四(关于接口类的作用)
这里我们还是以房产信息管理系统的题目举例: 发现在DAO层和service层都有接口类(注:impl是实现类) 为什么要用接口,不直接写实现类: 1.简单.规范性:这些接口不仅告诉开发人员你需要实现那 ...
- Salesforce LWC学习(四十六) 自定义Datatable实现cell onclick功能
本篇参考:https://developer.salesforce.com/docs/component-library/bundle/lightning-datatable 背景:我们有时会有这种类 ...
- 将mysql的输出文本写回mysql
1 准备工作 1.1 环境准备 操作系统:Microsoft Windows 10 专业工作站版 软件版本:Python 3.9.6 第三方包: pip install pandas2.1.0 pip ...
- [USACO2007OPEN G]Cheapest Palindrome
题目描述 Keeping track of all the cows can be a tricky task so Farmer John has installed a system to aut ...
- [ABC263F] Tournament
Problem Statement $2^N$ people, numbered $1$ to $2^N$, will participate in a rock-paper-scissors tou ...
- 前端传递Base64字符串,后端转流存入OSS
工具类 public static BufferedInputStream base64Convert(String base64) { // 解码 base64 = base64.split(&qu ...
- ElasticSearch之Health API
查看当前集群全部健康指标的信息,执行如下命令: curl -X GET "https://localhost:9200/_health_report?pretty" --cacer ...
- [VMware]ESXI下硬盘的两种直通方式
文章来自:https://rmbz.net/archives/vmware-esxi-passthrough 最近再搞ESXI,把原来的"黑群晖"改成ESXI:因为群晖里有数据,为 ...
- fence的使用
一.创建一个集群及pcs安装 1.真机切换root用户下 2.打开PC管理器视图 1.安装pcs,关掉防火墙,重启pcs和下次开机自动启动pcs 1.创建一个集群,用户:hacluster:密码:re ...