如何建立多语言的特拉维斯 CI

我的项目同时使用 nodejs 和 java

我尝试从 node _ js 构建开始,然后安装 java (因为这是一个 npm 模块)

但是安装 java 的脚本失败了,而且我不认为有必要安装它,当有一个已经存在的 java 构建。

我应该从一个 java 构建开始,然后安装节点吗?

我在尝试

language: java
- oraclejdk8
language: node_js
node_js:
- "0.10"

它忽略了前两行,构建了一个 node _ js build,其中包含 java 7 我的项目用的是 java 8

我试过这个 回答的蟒蛇

使用

language: node_js
node_js:
- "0.10"
java: oraclejdk8

但没成功

我怎样才能添加 java 8?

28673 次浏览

I used this .yml:

language: java
jdk:
- oraclejdk8
node_js: "0.10"
install: "npm install"
script: "npm test"

You can't add multiple languages, which explains the behavior you are seeing, and the node_js setting will only be recognized in a node language project. What you can do is utilize the incorporated nvm in TravisCI. For example, you can include - nvm install 0.10 - nvm use 0.10 in your before_install section to download the latest v0.10.x release of node.

On a Travis Java build environment, you can use nvm to manage Node.js runtimes:

.travis.yml

language: java


jdk:
- oraclejdk8


env:
- NODE_VERSION="0.12"


before_install:
- nvm install $NODE_VERSION

If your Node version is very recent, you might have to update nvm too.

To update nvm, write this in your .travis.yml:

before_install:
- wget https://raw.githubusercontent.com/creationix/nvm/v0.31.0/nvm.sh -O ~/.nvm/nvm.sh
- source ~/.nvm/nvm.sh
- nvm install 5 # for Node v5
- node --version

The above example shows how to first update to nvm v0.31, to then obtain Node v5.

It seems to be possible now to run several languages in one .travis.yml file using the jobs:include feature. As an example, my Github repo is arranged as follows:

project/ - top-level github directory
project/backend - Python backend
project/backend/tests - Python tests
project/android/AppName - Android app
project/ios/AppName - iOS app

Here is the .travis.yml, which runs tests in Python, Java, and Objective-C:

jobs:
include:
- language: python
python: 2.7
before_script:
- cd backend/tests
script:
- python -m unittest discover


- language: android
dist: trusty
jdk: oraclejdk8
android:
components:
- tools
- android-25
- build-tools-25.0.3
before_script:
- cd android/AppName
script:
- ./gradlew build connectedCheck


- language: objective-c
os: osx
osx_image: xcode8.3
before_script:
- cd ios/AppName
script:
- xcodebuild -workspace AppName.xcworkspace -scheme AppName
-destination 'platform=iOS Simulator,name=iPhone 7,OS=10.3' build test


notifications:
email:
- yourname@gmail.com

It seems you can build as many different configurations as you like using this feature, by treating each entry in the matrix as a top level config. Of course, if you have any parameters you want to set that apply to all languages, you can do that at the top level, as I do here with the notifications:email section.

When it is all set up, then on each build, you get something like this. Boom.

enter image description here

My project has a Python/Django backend and a JS/Vue frontend like below:

├── backend
│   ├── api
│   │   ├── tests
├── daemon
│   ├── frontend
│   │   ├── test

The idea is to run each test suite in a matrix' job, one for Python/Django tests and the other for JS ones:

matrix:
include:
- language: python
python:
- 3.4
before_install:
- cd backend/
install:
- pip install -r requirements.txt
script:
- python manage.py test


- language: node_js
node_js:
- 4.8
before_install:
- cd daemon/frontend
install:
- yarn install
script:
- yarn test


notifications:
email: false

See also

As per the documentation,

jobs:
include:
- language: python
python: 3.8
script:
- python -c "print('Hi from Python!')"


- language: node_js
node_js: 12
script:
- node -e "console.log('Hi from NodeJS!')"


- language: java
jdk: openjdk8
script:
- javac -help

Here's a production example.