Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Node - Passing variables into the GULP task

danblack2
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 28, 2016

My current code uses the command line argument delimiter to set a property in a gulp file

gulp --AssemblyInfoVersion "1.2.3"

I pick up the set variable inside the gulp.js with 

var version = gutil.env.AssemblyInfoVersion

 

Inside the Gulp build task, I tried to use the field Environment Variables to set AssemblyInfoVersion, but that does not seem to work. 

AssemblyInfoVersion="1.0.${bamboo.buildnumber}"

How do I access the Environment Variables via the build task?, or how do I pass the variables?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
rsperafico
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 28, 2016

Hello Dann,

If you look at the build log generated, you can find the command Bamboo is executing. In the log entry below, you can notice the Environment Variables under Advanced options is not appended to the command executed:

command	28-Dec-2016 14:31:12	Beginning to execute external process for build 'Project - Plan - Default Job #8 (PROJ-PLAN-JOB1-8)'\n ... running command line: \n/usr/local/bin/node node_modules/gulp/bin/gulp.js scripts\n

Instead, you need to pass the arguments directly into the Task:

command	28-Dec-2016 14:32:45	Beginning to execute external process for build 'Project - Plan - Default Job #9 (PROJ-PLAN-JOB1-9)'\n ... running command line: \n/usr/local/bin/node node_modules/gulp/bin/gulp.js scripts --env production --buildNumber 9\n
// npm install gulp yargs gulp-if gulp-uglify gulp-minify-css gulp-rename
var gulp   = require('gulp');
var args   = require('yargs').argv;
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var minifyCss = require("gulp-minify-css");
var rename = require('gulp-rename');
var isProduction = args.env === 'production';
var buildNumber = (args.buildNumber === "undefined") ? 0 : args.buildNumber;

// task
gulp.task('scripts', function () {
    gulp.src('./css/sample.css') // path to your file
    .pipe(gulpif(isProduction, minifyCss({keepBreaks: true})))
    .pipe(rename({
            suffix: '.' + buildNumber + '.min'
        }))
    .pipe(gulp.dest('./css/minified'));
});
body {
  background-color: white
}
div {
  width: auto;
}

 

image2016-12-28 14:35:0.png

 

 

scripts --env production --buildNumber ${bamboo.buildNumber}

information Please, notice the Bamboo variable must be ${bamboo.buildNumber} and not ${bamboo.buildnumber} as you mentioned.

As a result, you will have:

body{background-color:#fff}
div{width:auto}

Kind regards,

Rafael

TAGS
AUG Leaders

Atlassian Community Events