我目前正在使用Cypress作为我的测试工具,并且在 gitlab ci 上运行它时遇到了一个小问题。
问题
我的赛普拉斯测试的一部分目前使用敏感的信用卡信息,所以当我将它上传到 gitlab 存储库时,我不得不尝试找出一种方法来阻止任何人查看所说的“敏感信息”。最终,我尝试利用 Gitlabs 方便的“秘密变量”功能。
在设置了我需要隐藏的所有变量之后,我进入了我的 gitlab-ci.yml 文件并进行了设置,以便 .gitlab-ci.yml 文件创建一个名为“cypress/support/PaymentCredentials”的新文件。 js”,并且在该文件中,所有敏感的付款信息都将存储为 javascript 变量(如下所示)
image: bahmutov/cypress-image
# caching node_modules folder
# https://about.gitlab.com/2016/03/01/gitlab-runner-with-docker/
cache:
paths:
- node_modules/
before_script:
- cypress verify
- "echo -e \"export default {CARDHOLDER_NAME: '$CARDHOLDER_NAME', CARD_CC: '$CARD_CC', CARD_CC_MONTH: '$CARD_CC_MONTH', CARD_CC_YEAR: '$CARD_CC_YEAR', CARD_CC_CCV: '$CARD_CC_CCV'}\" > cypress/support/PaymentCredentials.js"
stages:
- build
- test
build-specs:
stage: build
script:
- npm install
artifacts:
paths:
- cypress/integration
.job_template: &e2e_test_definition
script:
- echo $CARDHOLDER_NAME
- export $CARDHOLDER_NAME
- cypress ci --spec "cypress/integration/$CI_BUILD_NAME.js"
Test_Project:
<<: *e2e_test_definition
所以在赛普拉斯中,我将集成文件设置为如下所示:
describe('Test', function(){
afterEach(function(){
})
beforeEach(function(){
})
//The entire job
context('Test - Full Functionality Test', function(){
it('Front-end Walkthrough', function(){
/*This is going to go through the first step on Test*/
stepOne()
/*This is going to go through the Second step on Test*/
stepTwo()
/*This is going to go through the Third step on Test*/
stepThree()
/*Page loads very slowly, needed some buffer*/
cy.wait(5000)
/*This is going to go through the Fourth step on Test*/
cy.then(function(){
cy
.get('[name=method]').select("CC") //select CC
.get('#name').type(CARDHOLDER_NAME)
.get('#number').type(CARD_CC)
.get('#month').select(CARD_CC_MONTH)
.get('#year').select(CARD_CC_YEAR)
.get('#ccv').type(CARD_CC_CCV)
.get('[type=checkbox]').check({force: true})
.get('#scoreboard-enroll-form').submit()
})
})
})
})
当我运行管道时,我仍然收到一个错误,指出“CARDHOLDER_NAME”尚未定义:
Gitlab ci build report
对于这种情况,是否有任何建议的方法?我是不是搞错了什么可笑的事情?
无论哪种方式,我都感谢任何帮助!