node.js - 从 Node.js 访问 Jenkins 凭证环境变量
问题描述
我已经使用 Jenkins 的凭据插件设置了一些凭据环境变量。我在我的 Jenkinsfile 中使用它们,如下所示:
pipeline {
agent any
environment {
DEV_GOOGLE_CLIENT_ID = credentials('DEV_GOOGLE_CLIENT_ID')
DEV_GOOGLE_CLIENT_SECRET = credentials('DEV_GOOGLE_CLIENT_SECRET')
}
stages {
stage('Install dependencies') {
steps {
dir("./codes") {
sh 'npm install'
}
}
}
stage('Stop previous forever process') {
steps {
dir("./codes") {
sh 'forever stop dev || ls'
}
}
}
stage('Clean forever logs') {
steps {
dir("./codes") {
sh 'forever cleanlogs'
}
}
}
stage('Test ') {
steps {
dir("./codes") {
sh 'npm run test'
}
}
}
}
}
在我的 Node.js 代码中,我试图通过编写 process.env.DEV_GOOGLE_CLIENT_SECRET 来访问这些环境变量,但这不起作用我越来越不确定......谢谢
解决方案
您使用了哪种类型的凭据:secret text
或username and password
?
使用username and password
时,您可以像这样分别获取用户名和密码
pipeline {
agent any
environment {
DEV_GOOGLE_CLIENT = credentials('DEV_GOOGLE_CLIENT')
}
stages {
stage('Get username and password') {
steps {
echo "username is $DEV_GOOGLE_CLIENT_USR"
echo "password is $DEV_GOOGLE_CLIENT_PSW"
}
}
}
我不知道如何在 node.js 中调用 $DEV_GOOGLE_CLIENT_USR 和 $DEV_GOOGLE_CLIENT_PSW,抱歉。
推荐阅读
- c# - 统一更新 Update() 中的属性值时的性能和优化
- python - AJAX 网页抓取时未接收到所有文本/json 数据
- acumatica - 寻求帮助使用 VFP 为 acumatica 开发 vfp API
- ios - 为什么需要将配置文件设置为用于调试和发布的分发?
- amazon-web-services - 结合 Azure Devops 和 AWS AutoScaling
- javascript - 尝试使用 javascript 创建汉堡菜单但代码未运行
- python - 将 Excel 文件导出为 PDF 格式而不丢失超链接功能
- c# - .Net Core 3 Blazor 服务器 - 如何使用声明进行基本登录?
- tableau-api - Tableau - 按品牌查找年销量最高的产品
- azure - Cosmos DB - 在 Where 条件下使用嵌套查询输出