2011年9月18日 星期日

Jenkins 設定 Email-ext plugin

基本設定

安裝 Email-ext plugin 後,Jenkins 專案設定會多一個 Editable Email Notification 的勾選,勾選後會多出其他選項

image

  • Global Recipient List - 收件人,可寄給多個收件人,用逗點或是空白隔開
  • Content Type - 信件內官為純文字格式或是HTML格式,預設為純文字格式
  • Default Subject - 信件主旨
  • Default Content - 信件內容,Jenkins 版本 2.9 之後提供了Jelly scripts 的樣板語言,讓使用者可以客製化信件的內容,現在的版本提供了三種範例:text, html, html-gamil
  • Attachments - 附件,可將整個 workspace 的內容或結果打包做為附件檔寄出

Jelly Content

客製化 Jelly scripts 是非常的簡單的一件事,只要依以下步驟即可

  1. 建置一個 Jelly scripts,副檔名為 .jelly;你可以在 $JENKINS_HOME\.plugin\email-ext\WEB-INF\classes\hudson\plugins\emailext\templates 找到 Jelly scripts 範例
  2. 新增 $JENKINS_HOME\.plugin\email-templates 目錄,將 Jelly scripts 放進這個目錄
  3. 在 Default Content 內容填入 ${JELLY_SCRIPT, template=”html”},Jenkins 在寄信時,就會以 $JENKINS_HOME\.plugin\email-templates\html.jelly 為樣版產生信件內容

以下的圖是官網提供 txt 與 html 的畫面範例:

txthtml

Jenkins/Hudson 手動安裝 Plugins 的步驟

Jenkins 提供了網路安裝 Plugins 的機制,但是在許多環境下,無法直接連線到 jenkins 網站安裝 plugins,以下介紹手動安裝 plugins 的步驟。

  1. 從 Jenkins/Hudson 網站下載 Plugin,副檔名為 .hdi
  2. 將 .hdi 複製到 $JENKINS_HOME/.plugin,一般來說 Windows 平台的 jenkins 工作路徑在 C:\.jenkins
  3. 重新啟動 jenkins

2011年2月25日 星期五

GWT-GWT.create() 限制

GWT.create() 不支援 class type 做為函式參數,再呼叫 GWT.create(clazz) 產生該類別實例的方式,需注意這個限制。以下範例在 GWT Development Mode 可執行,在 Comple 為 Javascript 時會有 Error。

public class MyFactory {

    public Foo makeFoo(Class<? extends Foo> clazz) {
        Foo ret = GWT.create(clazz);
        return ret;
    }
}

2011年2月19日 星期六

Msysgit/MinGW 32中文亂碼與輸入問題

解決中文顯示問題

修改 C:\Program Files (x86)\Git\etc\profile 加入以下設定

alias ls='/bin/ls --show-control-chars -F --color=tty'
解決中文輸入問題

修改 C:\Program Files (x86)\Git\etc\inputrc 加入以下設定

# disable/enable 8bit input
set meta-flag on
set input-meta on
set output-meta on
set convert-meta off

2011年2月12日 星期六

實作 Javascript String trim(), startsWith() 與 endWith()

String 類別是最常用的類別,但在 javascript 中並非提供基本函式,像是 substr(), trim(), startsWith() 等,這篇文章示範如何實作 Javascript String 類別的 buildin 函式

     myVar = substr2(myVar, x, y); //Your function
    myVar = myVar.substr(x, y); //built-in function

Trim()

    String.prototype.trim = function(){return 
    (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}

startsWith()

    String.prototype.startsWith = function(str) 
    {return (this.match("^"+str)==str)}

endsWith()

    String.prototype.startsWith = function(str) 
    {return (this.match("^"+str)==str)}

接著就可以用 build-in 的方式,呼叫這幾個函式

    var myStr = "Earth is a beautiful planet";
    var myStr2 = myStr.trim();  
    //=="Earth is a beautiful planet";
  
    if (myStr2.startsWith("Earth")) // returns TRUE
  
    if (myStr2.endsWith("planet")) // returns TRUE
  
    if (myStr.startsWith("Earth")) 
    // returns FALSE due to the leading spaces…
      
    if (myStr.endsWith("planet")) 
    // returns FALSE due to trailing spaces…