zuul-jobs/playbooks/buildproject.yaml
Saul Wold b4e1802a66 Update ansible job
Since we are now storing the _service in OBS, use it instead of
constructing the file. Clean-up the unused code.

Initial testing with fault, more to come.

Story: 2006673
Task: 36943
Change-Id: Ic9cd73ee31d213550263b415670b0bcae8953236
Signed-off-by: Saul Wold <sgw@linux.intel.com>
2019-10-07 15:39:59 -07:00

218 lines
5.7 KiB
YAML

- hosts: all
vars:
project_ver: 1.0
src_project: "Cloud:StarlingX:2.0"
target_project: "home:saulwold:sandbox-{{ target_distro }}"
test_project: "{{ target_project }}-{{ project_ver }}"
stx_project_desc: ""
stx_url: ""
osc_user: "saulwold"
osc_register: osc_result
obs_projects: []
spec_dirs: []
sorted_dirs: []
osc_key_key: "@ub@FB7OZxs391wt"
tasks:
- name: Print OS Family
debug:
msg: "OS distribution: {{ ansible_distribution }}"
- name: Setup local distro flag CentOS
set_fact:
target_distro: centos
when: ansible_distribution == "CentOS"
- name: Setup local distro flag openSUSE
set_fact:
target_distro: opensuse
when: ansible_distribution == "openSUSE Leap"
- name: Setup local directories when not using zuul
set_fact:
top_dir: /test
src_dir: /test
when: zuul is not defined
- name: Setup local directories from zuul data
set_fact:
top_dir: "{{ zuul.executor.src_root }}"
src_dir: "{{ zuul.project.src_dir }}"
when: zuul is defined
- name: Print OS Family
debug:
msg: "OS distribution: {{ ansible_distribution }} {{ target_distro }}"
- name: Get OSC Command
import_role:
name: osc
tasks_from: install_osc
- name: Create temporary directory
tempfile:
state: directory
prefix: stx.
register: stx_pkg_tmpdir
- name: Setup oscrc file
import_role:
name: osc
tasks_from: create_oscrc
- name: OSC Version
import_role:
name: osc
vars:
osc_options: "--version"
register: osc_version
- name: Clean OSC Project
import_role:
name: osc
vars:
osc_options: rdelete -r -m 'rpm-packing CI Cleanup' {{ test_project }}
ignore_errors: yes
- name: Create Project
import_role:
name: osc
tasks_from: create_meta
- name: Freeze Project
import_role:
name: osc
tasks_from: freeze
- name: Init Project
import_role:
name: osc
vars:
osc_options: init {{ test_project }}
- name: Add prjconf
import_role:
name: osc
tasks_from: create_prjconf
when: target_distro == "centos"
- name: Find local directories with spec files
find:
paths: "{{ src_dir }}"
hidden: false
file_type: directory
patterns: "{{ target_distro }}"
recurse: yes
register: specfiles
- name: Generate Repo name
set_fact:
repo_name: "{{ specfiles.files.0.path.split('/')[-3] }}"
- name: Generate Repo Dir
set_fact:
repo_dir: "{{ src_dir}}/{{ repo_name }}"
- debug:
msg: "{{ repo_name }}: {{ repo_dir }} "
- name: List spec files
debug:
msg: "Specfile List: {{ specfiles }}"
- name: Create Project list
set_fact:
spec_dirs: "{{ spec_dirs }} + [ '{{ item.path.split('/')[-2] }}' ]"
with_items: "{{ specfiles.files }}"
- name: Sort directories
set_fact:
sorted_dirs: "{{ spec_dirs | sort | unique }}"
- name: "list Sorted Directories"
debug:
msg: "Sorted Directories: {{ item }}"
with_items: "{{ sorted_dirs }}"
- name: OSC Link Package
import_role:
name: osc
tasks_from: linkpackage
- name: OSC detachbranch
import_role:
name: osc
tasks_from: detachbranch
# pushd ./out
# sleep 5
# # Check if there is no change, then pretent success
# if [ $($osc_timed ls ${{OBS_TEST_PROJECT}} | wc -l) -lt 1 ]; then
# echo "Apparently there is no change... claiming SUCCESS"
# exit 0
# fi
#
# while true; do
# unset pending
# unset failed
# unset kickscheduler
# unset succeeded
# res=`osc results --csv -r standard`
# if [ $? -ne 0 ]; then
# sleep 5
# continue
# fi
# echo "... $(date): "
# for r in $res; do
# # some failures?
# if [[ $r =~ broken$ ]]; then
# echo "ignoring OBS broken state"
# echo $r
# continue
# fi
# # some failures?
# if [[ $r =~ (failed$|unresolvable$) ]]; then
# echo $r
# failed=1
# fi
# # still pending builds?
# if [[ $r =~ (blocked$|scheduled$|dispatching$|building$|signing$) ]]; then
# pending=1
# fi
# # scheduler stuck?
# if [[ $r =~ (finished$|unknown$|outdated$) ]]; then
# kickscheduler=1
# fi
# # found something?
# if [[ $r =~ succeeded$ ]]; then
# succeeded=1
# fi
# done
#
# if [ -n "$kickscheduler" ]; then
# echo "# $(date)" | osc meta prjconf -F - ${{OBS_TEST_PROJECT}}
# sleep $((RANDOM%60+30))
# echo "kicking scheduler"
# continue
# fi
#
# if [ -n "$pending" ]; then
# sleep $((RANDOM%50+30))
# echo ""
# continue
# fi
#
# if [ -n "$failed" ]; then
# echo "Build failed :-("
# exit 1
# elif [ -n "$succeeded" ];
# break
# fi
# done
#
# - name: Clean-up tmp directory
# file:
# path: "{{ stx_pkg_tmpdir.path }}"
# state: absent
# when: stx_pkg_tmpdir.path is defined