title: Use Global Variable to Set Build Output Path in Grunt
body: <p>I have a couple grunt tasks and I am trying to share global variables across those tasks and I am running into issues.</p>
  
  <p>I have written a some custom tasks which set the proper output path depending on the build type. This seems to be setting things correctly.</p>
  
  <pre><code>// Set Mode (local or build)
  grunt.registerTask("setBuildType", "Set the build type. Either build or local", function (val) {
    // grunt.log.writeln(val + " :setBuildType val");
    global.buildType = val;
  });
  
  // SetOutput location
  grunt.registerTask("setOutput", "Set the output folder for the build.", function () {
    if (global.buildType === "tfs") {
      global.outputPath = MACHINE_PATH;
    }
    if (global.buildType === "local") {
      global.outputPath = LOCAL_PATH;
    }
    if (global.buildType === "release") {
      global.outputPath = RELEASE_PATH;
    }
    if (grunt.option("target")) {
      global.outputPath = grunt.option("target");
    }
    grunt.log.writeln("Output folder: " + global.outputPath);
  });
  
  grunt.registerTask("globalReadout", function () {
    grunt.log.writeln(global.outputPath);
  });
  </code></pre>
  
  <p>So, I'm trying to then reference global.outputPath in a subsequent task, and running into errors.</p>
  
  <p>If I call <code>grunt test</code> from the command line, it outputs the correct path no problem.</p>
  
  <p>However, if I have a task like this:
      clean: {
        release: {
          src: global.outputPath
        }
      }</p>
  
  <p>It throws the following error:
  <code>Warning: Cannot call method 'indexOf' of undefined Use --force to continue.</code></p>
  
  <p>Also, my constants in the setOutput task are set at the top of my Gruntfile.js</p>
  
  <p>Any thoughts? Am I doing something wrong here?</p>