psuvjd / jenkins deploy auto add debug port

// ==UserScript==
// @name            jenkins deploy auto add debug port
// @namespace       https://openuserjs.org/users/psuvjd
// @description     Set debug port when deploy with jenkins.
// @copyright       2020, psuvjd (https://openuserjs.org/users/psuvjd)
// @license         MIT
// @version         1.0.14
// @grant           none
// @author          psuvjd
//
// @match           https://jenkins.int.ybm100.com/view/YKQ/job/YKQ-*/job/*/build*
// @match           https://ci.test.ybm100.com/job/INVT/job/INVT-BE-*/job/*/build*
// @match           https://ci.int.ybm100.com/job/INVT/job/INVT-BE-*/job/*/build*
// @exclude         https://jenkins.int.ybm100.com/view/YKQ/job/YKQ-prod/job/*/build*
//
// @updateURL       https://openuserjs.org/meta/psuvjd/jenkins_deploy_auto_add_debug_port.meta.js
// @downloadURL     https://openuserjs.org/install/psuvjd/jenkins_deploy_auto_add_debug_port.user.js
// ==/UserScript==

// ==OpenUserJS==
// @author          psuvjd
// ==/OpenUserJS==

(function () {
  'use strict';

  setInterval(doReal, 200);

  let opDone = false;

  function doReal() {

    if (opDone) {
      return;
    }

    if (document.querySelector(".behavior-loading") && document.querySelector(".behavior-loading").style.display != "none") {
      // console.log("载入中...");
      return;
    }

    let debugPortMap = {
      "xyy-electronic-signatures-all": 19090,
      "xyy-electronic-signatures-web": 19091,
      "xyy-map-manager": 19092,
      "xyy-ykq-business-all": 18999,
      "xyy-ykq-drugstore-medicines-all": 18899,
      "xyy-ykq-inquiry-all": 19072,
      "xyy-ykq-message-all": 19096,
      "ykq-healthy-note-service": 18095,
      "ykq-marketing-job": 19009,
      "ykq-order-center": 19001,
      "ykq-order-job": 19003,
      "ykq-order-pay": 19002,
      "ykq-tuangou": 18092,
      "ykq-tuangou-manager": 18093,
      "ykq-tuangou-timetask": 18094,
      "ykq-order-logistic": 19012,
      "ykq-health-platform": 19015,
      "ykq-order-center-export": 29009,
      "ykq-order-query": 29013,
      "": 1,
      "ykq-order-mq": 29091,
      "ykq-order-settle": 19005,
      "saas-remote-prescription-api": 38000,
      "xyy-saas-remote-web-all": 39049
    }

    let debugPortSelector = document.querySelector("input[value='DEBUG_PORT']").nextElementSibling;
    let debugPortOriVal = debugPortSelector.value;
    if (debugPortOriVal && debugPortOriVal != "") {
      // console.log("有值了");
      return;
    }

    let jobName = getJobName();
    let debugPort = debugPortMap[jobName];
    if (!debugPort) {
      console.log("cannot find debug port, job: " + jobName);
      opDone = true;
      return;
    }
    debugPortSelector.value = debugPort;
    opDone = true;
    console.log("debug port set done, port: " + debugPort);
    // document.querySelector(".behavior-loading").each((idx, e) => e.style.display='none');
  };

  function getJobName() {
    let url = window.location.href;
    return url.match(/com.*\/job\/(\S+[-\S+]*)\/build/)[1];
  }

})();