aboutsummaryrefslogtreecommitdiffstats
path: root/deployment/onap-lab-ci/heat/jenkins/jenkins_vm_config.yaml
blob: 0bf6347a95c18e2c30eb0d8fdd12266e9c6046bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#cloud-config
# vim: syntax=yaml
write_files:
- path: /opt/format-disks
  permissions: '0700'
  content: |
    #!/bin/bash
    voldata_id="%voldata_id%"
    voldata_dev="/dev/disk/by-id/virtio-$(echo ${voldata_id} | cut -c -20)"
    mkfs.ext4 ${voldata_dev}
    mkdir -pv /var/lib/jenkins
    echo "${voldata_dev} /var/lib/jenkins ext4 defaults 1 2" >> /etc/fstab
    mount /var/lib/jenkins
- path: /opt/jenkins_vm_entrypoint.sh
  permissions: '0755'
  content: |
    #!/bin/bash -x

    printenv

    echo `hostname -I` `hostname` >> /etc/hosts

    function restart_jenkins() {
      sudo systemctl restart jenkins
      sleep 1
      echo -n "Restarting jenkins"
      until $(curl --output /dev/null --silent --head --fail http://localhost:8080/login); do
        printf '.'
        sleep 3
      done
      echo
      sleep 1
    }

    cp ~ubuntu/.ssh/authorized_keys /root/.ssh

    cat > /etc/apt/apt.conf.d/90curtin-aptproxy<<EOF
    Acquire::http::Proxy "http://10.145.122.117:8000/";
    EOF

    apt-get update

    cat >> /etc/inputrc <<EOF
    set show-all-if-ambiguous on
    set show-all-if-unmodified on
    set match-hidden-files off
    set mark-symlinked-directories on
    EOF

    export HOME=/root
    apt-get -y install git
    git config --global user.email "jenkins@localhost"
    git config --global user.name "jenkins"
    apt-get -y install etckeeper
    apt-get -y install curl openjdk-8-jre unzip python3-openstackclient python3-heatclient python3-jenkins-job-builder jq openvpn python3-pip xmlstarlet tree
    pip3 install robotframework

    # install Jenkins
    wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
    sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
    apt-get update
    apt-get -y install jenkins

    mkdir -p ~jenkins/.ssh
    cp ~ubuntu/.ssh/authorized_keys ~jenkins/.ssh
    chown -R jenkins:jenkins ~jenkins/.ssh

    su -l jenkins -c "/opt/jenkins-init-1.sh"

    restart_jenkins

    su -l jenkins -c "/opt/jenkins-init-2.sh"

    restart_jenkins

- path: /opt/jenkins-init-1.sh
  permissions: '0755'
  content: |
    #!/bin/bash -x

    git config --global user.email "jenkins@localhost"
    git config --global user.name "jenkins"

    cd ~jenkins

    cp /etc/skel/.profile .
    cat > .bashrc <<EOF
    alias ls='ls --color -F'
    EOF

    git init

    git add -A
    git commit -m 'Initial installation config' > /dev/null

    rm -f secrets/initialAdminPassword
    rm -rf users/admin
    rsync -avP /opt/jenkins/ .

    git add -A
    git commit -m 'Set up jenkins user' > /dev/null

- path: /opt/jenkins-init-2.sh
  permissions: '0755'
  content: |
    #!/bin/bash -x

    cd ~jenkins
    ln -s /var/cache/jenkins/war/WEB-INF/jenkins-cli.jar

    sleep 20
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin git
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin ws-cleanup
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin envinject
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin gerrit-trigger
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin robot
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin postbuildscript
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin timestamper
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin build-blocker-plugin
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin build-timeout
    java -jar jenkins-cli.jar -s http://localhost:8080/ -auth jenkins:jenkins install-plugin influxdb

    git add -A
    git commit -m 'Install initial plugins' > /dev/null

    git clone https://github.com/garyiwu/onap-lab-ci.git
    cd onap-lab-ci
    jenkins-jobs update -r jjb

- path: /opt/jenkins/jenkins.install.InstallUtil.lastExecVersion
  content: |
    2.46.3
- path: /opt/jenkins/users/jenkins/config.xml
  content: |
    <?xml version='1.0' encoding='UTF-8'?>
    <user>
      <fullName>jenkins</fullName>
      <properties>
        <jenkins.security.ApiTokenProperty>
          <apiToken>{AQAAABAAAAAwQAGpldGajxw//dhxd53gZGv4w0JnZYDETTLBQdpotQXt02s0lq13YrhyaytbLFMflb98hzWY9YBlDIThZt7u+Q==}</apiToken>
        </jenkins.security.ApiTokenProperty>
        <com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty plugin="credentials@2.1.13">
          <domainCredentialsMap class="hudson.util.CopyOnWriteMap$Hash"/>
        </com.cloudbees.plugins.credentials.UserCredentialsProvider_-UserCredentialsProperty>
        <hudson.model.MyViewsProperty>
          <views>
            <hudson.model.AllView>
              <owner class="hudson.model.MyViewsProperty" reference="../../.."/>
              <name>all</name>
              <filterExecutors>false</filterExecutors>
              <filterQueue>false</filterQueue>
              <properties class="hudson.model.View$PropertyList"/>
            </hudson.model.AllView>
          </views>
        </hudson.model.MyViewsProperty>
        <org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty plugin="display-url-api@2.0">
          <providerId>default</providerId>
        </org.jenkinsci.plugins.displayurlapi.user.PreferredProviderUserProperty>
        <hudson.model.PaneStatusProperties>
          <collapsed/>
        </hudson.model.PaneStatusProperties>
        <hudson.search.UserSearchProperty>
          <insensitiveSearch>false</insensitiveSearch>
        </hudson.search.UserSearchProperty>
        <hudson.security.HudsonPrivateSecurityRealm_-Details>
          <passwordHash>#jbcrypt:$2a$10$Esc9z/mnK/CQ8crgFbE3/eP1EI6pvzIHRBe3SSik7rrNt.DDftON2</passwordHash>
        </hudson.security.HudsonPrivateSecurityRealm_-Details>
        <hudson.tasks.Mailer_-UserProperty plugin="mailer@1.20">
          <emailAddress>jenkins@localhost</emailAddress>
        </hudson.tasks.Mailer_-UserProperty>
      </properties>
    </user>

runcmd:
- /opt/format-disks
- /opt/jenkins_vm_entrypoint.sh