2016-08-26 10 views
2

私はジェンキンをインストールし、複数のスクリプトを実行するためにcli.jarを実行する必要があります。それは、シェルコマンドを使って設定する必要のあるjnlpポートが必要です。しかし、それは失敗しているようです。コマンド行からjenkinsのjnlpポートを設定する方法は?

-vvvオプションで実行
- name: Set jnlp port 
    shell: 'curl -X POST -d ".useSecurity=on&slaveAgentPort.type=fixed&value=49187&core%3Aapply=true&json=%7B%22useSecurity%22%3A+%7B%22slaveAgentPort%22%3A+%7B%22type%22%3A+%22fixed%22%2C+%22value%22%3A+%2249187%22%7D%7D%2C+%22core%3Aapply%22%3A+%22true%22%7D" --header "Content-Type:application/x-www-form-urlencoded" http://localhost:8080//configureSecurity/configure' 
    remote_user: jenkins 
    become: yes 
    become_method: sudo 

ができます:

ERROR! Syntax Error while loading YAML. 


The error appears to have been in '/vagrant/ansible/roles/jenkins1.648/tasks/plugins.yml': line 37, column 370, but may 
be elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

- name: Check update center and push it to the update URL 
    shell: 'curl -X POST -d .useSecurity=on&slaveAgentPort.type=fixed&value=49187&core%3Aapply=true&json=%7B%22useSecurity%22%3A+%7B%22slaveAgentPort%22%3A+%7B%22type%22%3A+%22fixed%22%2C+%22value%22%3A+%2249187%22%7D%7D%2C+%22core%3Aapply%22%3A+%22true%22%7D" --header "Content-Type:application/x-www-form-urlencoded" http://localhost:8080//configureSecurity/configure' -vvv 
                                                                                               ^here 
This one looks easy to fix. It seems that there is a value started 
with a quote, and the YAML parser is expecting to see the line ended 
with the same kind of quote. For instance: 

    when: "ok" in result.stdout 

Could be written as: 

    when: '"ok" in result.stdout' 

Or equivalently: 

    when: "'ok' in result.stdout" 
We could be wrong, but this one looks like it might be an issue with 
unbalanced quotes. If starting a value with a quote, make sure the 
line ends with the same set of quotes. For instance this arbitrary 
example: 

    foo: "bad" "wolf" 

Could be written as: 

    foo: '"bad" "wolf"' 

Ansible failed to complete successfully. Any error output should be 
visible above. Please fix these errors and try again. 
+0

@techraf:はい私はコマンドラインから実行しようとしました。 –

+0

@techraf curlコマンドの終了後に-vvvを追加しています。あなたはそれが期待される方法を具体化してください –

+0

さて、私はちょうどジェンキンでTCP/jnlpポートを設定したいと思います。同じcurlコマンドは直接的にはうまく動作しますが、不可能ではありません。私はそれがなぜ失敗しているのかを解明しようとしています。 –

答えて

2

あなたはansible経由ジェンキンス-cliのグルーヴィーなコマンドを呼び出すと大丈夫であれば、これは私の作品:

def instance=jenkins.model.Jenkins.instance 
instance.setSlaveAgentPort(9999) 
instance.save() 

Ansibleタスク次のようになります。

- name: Set jnlp port 
    shell: 'java -jar /tmp/jenkins-cli.jar -s http://localhost:8080 groovy /tmp/fix-jnlp-port.groovy' 
    remote_user: jenkins 
    become: yes 
    become_method: sudo 

明らかに、あなたはjenkins-cli.jarファイルをダウンロードし、事前にjavaをインストールしておく必要があります。

これは、JNLPポートがJenkinsによって(いくつかのヘッダー経由で)送信され、ローカルでアクセスできることを前提としています。

また、curlを使ってスクリプトコンソールにそのGroovyコードを渡すこともできます(これは試していません)。このリンクを共有する例: https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+Script+Console

curl --data-urlencode "script=$(<./somescript.groovy)" http://jenkins/scriptText 

そして、ちょうどGET_URLとURI ansibleモジュールを試すこと自由に感じ、カールに依存関係を削除します。

+0

これは興味深いようです。それを試みます。ありがとう! –

+0

ポートを永久にセットアップするか、それともそのポートをスクリプト用に一時的に使用しますか –

+0

instance.save()は、ジェンキンプロセスの再起動中も永続化されます。これを省略すると、jnlpポートは、jenkinsプロセスがシャットダウンするまでのみ設定されます。言い換えれば、それはグルーヴィースクリプトの実行ではありません。 –

関連する問題