前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Jenkins 凭据使用

Jenkins 凭据使用

作者头像
SpiritLing
发布2020-07-20 10:13:28
1.2K0
发布2020-07-20 10:13:28
举报
文章被收录于专栏:SpiritLingSpiritLing

原文链接:https://blog.spiritling.cn/posts/6b626a8a/

环境变量

jenkinsfile 使用环境变量

代码:

代码语言:javascript
复制
pipeline {
  agent {
    docker {
      image 'spiritling/node:10.15.3'
    }

  }
  stages {
    stage('get') {
      environment {
        VERSION = sh(script: 'node script/auto-versioning.js', , returnStdout: true)
      }
      steps {
        sh 'echo "VERSION: "$VERSION'
    }
  }
}

将 auto-versioning.js 执行后返回的文本或数字存入到 VERSION 环境变量中去

steps 中使用 $VERSION 来获取环境变量

凭据

账号密码凭据管理

创建凭据,以下为例子:

类型:Username with password 范围:全局 用户名:root 密码:rootxxxx ID:BIRRARY_ID 描述:随意填写

在 jenkinsfile 中使用

代码语言:javascript
复制
pipeline {
  agent {
    docker {
      image 'spiritling/node:10.15.3'
    }

  }
  stages {
    stage('get') {
      steps {
        withCredentials([usernamePassword(credentialsId: 'BIRRARY_ID', passwordVariable: 'password', usernameVariable: 'username')]) {
          sh 'git remote set-url origin https://${username}:${password}@github.com/spiritling/blog.git'
        }
        sh 'echo "获取凭据"'
    }
  }
}

可以在 jenkinsfile 文件的构建过程中获取到 username 和 password 的凭据,并且可以在后续将其插入进去

加密文本凭据管理

创建凭据,以下为例子:

类型:Secret text 范围:全局 Secret:rootxxxx ID:BIRRARY_ID 描述:随意填写

在 jenkinsfile 中使用

代码语言:javascript
复制
pipeline {
  agent {
    docker {
      image 'spiritling/node:10.15.3'
    }

  }
  stages {
    stage('get') {
      steps {
        withCredentials([string(credentialsId: 'ID:BIRRARY_ID', variable: 'secret')]) { //set SECRET with the credential content
          sh 'echo -e "registry=https://npmjs.org/spiritling/\n_auth = ${secret}\nemail = spirit_ling_cn@163.com\nalways-auth = true\n$PATH" > .npmrc'
        }
        sh 'echo "获取凭据"'
    }
  }
}

可以在 jenkinsfile 文件的构建过程中获取到 secret 的凭据,并且可以在后续将其插入进去

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-07-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 环境变量
    • jenkinsfile 使用环境变量
    • 凭据
      • 账号密码凭据管理
        • 加密文本凭据管理
        相关产品与服务
        容器服务
        腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档