如何在PowerShell构建步骤中获得TeamCity工作目录

时间:2016-05-17 18:56:50

标签: powershell teamcity teamcity-9.0

在我的TeamCity项目中,我有一个PowerShell构建步骤,我需要在脚本中获取团队城市的当前工作目录。我尝试使用此代码从环境变量中获取它,但是,环境变量显然是null

"Working Dir: " + $env:teamcity_build_workingDir

如何访问TeamCity变量,或者如何获取TeamCity项目的当前工作路径?

1 个答案:

答案 0 :(得分:2)

根据TeamCity jsfiddle$pwd - 属性没有环境变量。

  

系统属性名称:teamcity.build.workingDir

     

环境变量名称:无

     

描述:启动构建的工作目录。   这是TeamCity构建运行器应该启动的路径   处理。这是一个特定于跑步者的属性,因此它有所不同   每个新步骤的价值。

您可以尝试Get-Location"Working Dir: " + $pwd "Working Dir: " + (Get-Location) ,它会返回PowerShell的当前工作目录。希望PowerShell进程在与build-runner相同的工作目录中启动。例如:

<script>
var interactiveSearch = {};
(function() {
  interactiveSearch.common = {
    init: function() {
      interactiveSearch.common.setupDataTableDefaults();
      $.ajaxSetup({
        cache: false
      });
    },
    setupDataTableDefaults: function() {
      $.extend($.fn.dataTable.defaults, {
        "sDom": "<'table-header-controls'<'row'<l><f>>r><i>t<'table-footer-controls'<'row'<'span12'p><'span12'i>>>",
        "sPaginationType": "bootstrap",
        "bJQueryUI": false,
        "bProcessing": false,
        "bServerSide": true,
        "fnServerData": interactiveSearch.common.getTableData
      });
    },
    getTableData: function(sSource, aoData, fnCallback) {
      var data = new Array();
      var columnCount = _.find(aoData, function(o) {
        return o.name == 'iColumns';
      }).value;
      var echo = _.find(aoData, function(o) {
        return o.name == 'sEcho';
      }).value;
      var skip = _.find(aoData, function(o) {
        return o.name == 'iDisplayStart';
      }).value;
      var take = _.find(aoData, function(o) {
        return o.name == 'iDisplayLength';
      }).value;
      var search = _.find(aoData, function(o) {
        return o.name == 'sSearch';
      }).value;
      var sortCols = _.filter(aoData, function(o) {
        return o.name.indexOf('iSortCol_') == 0;
      });
      var sortDirs = _.filter(aoData, function(o) {
        return o.name.indexOf('sSortDir_') == 0;
      });
      var searches = _.filter(aoData, function(o) {
        return o.name.indexOf('sSearch_') == 0;
      });
      data.push({
        "name": "TableEcho",
        "value": echo
      });
      data.push({
        "name": "Skip",
        "value": skip
      });
      data.push({
        "name": "Take",
        "value": take
      });
      data.push({
        "name": "AllSearch",
        "value": search
      });
      var actual = 0;
      _.each(sortCols, function(columnSort, sortIndex) {
        var columnIndex = columnSort.value;
        var columnSearch = searches[columnIndex].value;
        var sortDir = sortDirs[sortIndex].value;
        data.push({
          "name": "Columns[" + actual + "].ColumnIndex",
          "value": columnIndex
        });
        data.push({
          "name": "Columns[" + actual + "].SortDirection",
          "value": sortDir
        });
        if (columnSearch != '') {
          data.push({
            "name": "Columns[" + actual + "].SearchTerm",
            "value": columnSearch
          });
        }
        actual++;
      });
      for (var i = 0; i < columnCount; i++) {
        var searchTerm = searches[i].value;
        if (searchTerm == '') {
          continue;
        }
        data.push({
          "name": "Columns[" + actual + "].ColumnIndex",
          "value": i
        });
        data.push({
          "name": "Columns[" + actual + "].SearchTerm",
          "value": searchTerm
        });
        actual++;
      }
      $.post(sSource, data)
        .success(fnCallback);
    }
  };
})();
$(function() {
  interactiveSearch.common.init();
});
(function() {
  var product = interactiveSearch.product = {};
  product.init = function() {
    product.initDataTable();
    product.bindEvents();
  };

  function convertFullRowToDataObject(fullRow) {
    return {
      Id: fullRow[0],
      ProductName: fullRow[1],
      Synonym: fullRow[2],
      Acronym: fullRow[3],
      CasNo: fullRow[4],
      EinecsNo: fullRow[5],
      Formula: fullRow[6],
      MolecularWeight: fullRow[7],
      Status: fullRow[8],
      MeltingPoint: fullRow[9],
      BoilingPoint: fullRow[10],
      HasDoc: fullRow[11] !== '',
      RelatedDocPath: product.baseUrl + fullRow[11],
      HasDImage: fullRow[12] !== '',
      ImagePath: product.baseUrl + fullRow[12]
    };
  }
  product.initDataTable = function() {
    product.productTable = $("#product-table").dataTable({
      aaSorting: [
        [1, "asc"]
      ],
      iDisplayLength: 15,
      bServerSide: true,
      bDestroy: true,
      sAjaxSource: interactiveSearch.product.listUrl,
      fnRowCallback: function(nRow, aData) {
        $(nRow).data('rowInfo', convertFullRowToDataObject(aData));
      },
      aoColumns: [{
        sType: "string",
        sClass: "dtAlignLeft",
        mData: 1
      }]
    });
  };
  product.bindEvents = function() {
    _.templateSettings = {
      interpolate: /\{\{(.+?)\}\}/g,
      evaluate: /\{\[([\s\S]+?)\]\}/g
    };
    var templateText = $('#productDetailTemplate').html(),
      compiledTemplate = _.template(templateText);
    $(document).on('click', '#product-table tr', function(e) {
      var el = $(this);
      var rowData = el.data('rowInfo');
      var html = compiledTemplate(rowData);
      $('#productDetailContainer').empty().html(html);
      $('#product-table tr').removeClass('active');
      el.addClass('active');
    });
    $('#searchClone').on('keyup', function(e) {
      var el = $(this);
      var mimicEl = $('#product-table_filter input');
      mimicEl.val(el.val()).trigger('keyup');
    })
    $('.btn-reset-filter').on('click', function() {
      $('#searchClone').val('').trigger('keyup');
    });
  };
})();
$(document).ready(function() {
  interactiveSearch.product.listUrl = '/pa/Product/ListItems';
  interactiveSearch.product.baseUrl = '/pa/';
  interactiveSearch.product.init();
});
</script>
相关问题