繁体   English   中英

如何在Travis CI中访问环境变量

[英]How do I access environment variables in Travis CI

我已经使用SQL Server和Node.js构建了一个站点,并使用Mocha和Chai进行了测试。 在本地一切正常,并且不需要访问数据库的任何测试都可以在Travis CI上正确运行,但是因为我的密码,用户名,数据库路径等存储在我的.env文件中,所以gitignored Travis可以做到。访问数据库进行测试。

我尝试根据Travis文档中的这些说明设置环境变量,但是登录失败。 我知道正在找到环境变量,因为错误消息是: Unhandled rejection SequelizeConnectionError: Login failed for user 'EventAdmin'. “ EventAdmin”是环境变量中的用户名,但是由于某些原因,密码未被接受。 我知道该密码是正确的,因为我是直接从.env文件复制它的。

我的.travis.yml文件如下所示:

 language: node_js node_js: - "4.1" - "4.0" - "0.12" - "0.11" - "0.10" - "iojs" before_install: - npm install -g grunt-cli script: grunt test 

我的测试(在本地工作)如下所示:

 'use strict'; var chai = require('chai'); var expect = chai.expect; var assert = chai.assert; var chaihttp = require('chai-http'); chai.use(chaihttp); require('../server.js'); describe('Test /showfullteam route', function() { it('should load all MS contacts from /showfullteam', function(done) { chai.request('localhost:3000') .get('/showfullteam') .end(function(err, res) { expect(err).to.eql(null); for (var i = 0; i < res.body.length; i++) { expect(res.body[i]).to.include.keys('firstName', 'lastName', 'email', 'newsletterSubscription', 'contactDescription', 'msTeamMember', 'msTeamTitle', 'showOnHomePage', 'headShot', 'company', 'address', 'country', 'interestId', 'allowNotifications', 'allowPersonalInfoSharing'); expect(res.body[i].msTeamMember).to.eql(true); expect(typeof res.body[i].firstName).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); expect(typeof res.body[i].lastName).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); expect(typeof res.body[i].email).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); if (res.body[i].newsletterSubscription) { assert.typeOf(res.body[i].newsletterSubscription, 'boolean'); } if (res.body[i].msTeamMember) { assert.typeOf(res.body[i].msTeamMember, 'boolean'); } if (res.body[i].showOnHomePage) { assert.typeOf(res.body[i].showOnHomePage, 'boolean'); } if (res.body[i].allowNotifications) { assert.typeOf(res.body[i].allowNotifications, 'boolean'); } if (res.body[i].interestId) { assert.isNumber(res.body[i].interestId); } expect(typeof res.body[i].contactDescription).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); expect(typeof res.body[i].headShot).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); expect(typeof res.body[i].company).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); expect(typeof res.body[i].address).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); expect(typeof res.body[i].country).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); expect(typeof res.body[i].allowPersonalInfoSharing).to.be.a('string') || expect(typeof res.body[i].firstName).to.be.a('null'); }; done(); }); }); }); 

您可以在我的GitHub存储库上看到完整的项目,并在Travis CI上看到失败的测试

如果您需要更多信息,请告诉我。 在此先感谢您提供的所有帮助!

我想出了如何设置环境变量,但这不是问题。 问题是SQL Server与travis不兼容。 我切换到mariadb ,测试通过了:-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM