Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _yeomanGenerator = _interopRequireDefault(require("yeoman-generator"));

var _jenkins = _interopRequireDefault(require("jenkins"));

var _formData = _interopRequireDefault(require("form-data"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

class JenkinsJobGenerator extends _yeomanGenerator.default {
  constructor(args, opts) {
    super(args, opts);
    this.option('url', {
      default: 'builder.internal.doodle-test.com',
      type: String
    });
    this.option('user', {
      default: 'create-jobs',
      type: String
    });
  }

  async prompting() {
    let create = this.config.get('create');

    if (create === undefined || create === false) {
      ({
        create
      } = await this.prompt({
        type: 'list',
        name: 'create',
        message: 'Create and configure job on Jenkins?',
        choices: [{
          name: 'Yes',
          value: true
        }, {
          name: 'No',
          value: false
        }],
        default: false
      }));
      this.config.set('create', create);
    }

    if (create) {
      const {
        token,
        job,
        repository,
        name,
        description
      } = await this.prompt([{
        type: 'password',
        name: 'token',
        message: 'API Token for user create-jobs',
        default: ''
      }, {
        type: 'string',
        name: 'job',
        message: 'Job name',
        default: this.config.get('repository'),
        store: true
      }, {
        type: 'string',
        name: 'repository',
        message: 'Repository name within organisation',
        default: this.config.get('repository'),
        store: true
      }, {
        type: 'string',
        name: 'name',
        message: 'Job display name',
        default: this.config.get('name'),
        store: true
      }, {
        type: 'string',
        name: 'description',
        message: 'Job description',
        default: this.config.get('description'),
        store: true
      }]);
      this.token = token;
      this.config.set('job', job);
      this.config.set('repository', repository);
      this.config.set('name', name);
      this.config.set('description', description);
    }
  }

  async writing() {
    if (this.config.get('create')) {
      const jenkins = (0, _jenkins.default)({
        baseUrl: `https://${this.options.user}:${this.token}@${this.options.url}`,
        formData: _formData.default,
        promisify: true
      });
      this.fs.copyTpl(this.templatePath('job.xml'), this.templatePath('template.xml'), {
        job: this.config.get('job'),
        repository: this.config.get('repository'),
        name: this.config.get('name'),
        description: this.config.get('description')
      });
      await jenkins.job.create(this.config.get('repository'), this.fs.read(this.templatePath('template.xml')));
      this.fs.delete(this.templatePath('template.xml'));
    }
  }

}

var _default = JenkinsJobGenerator;
exports.default = _default;
module.exports = JenkinsJobGenerator;