const path = require('path'); module.exports = { tags: async (tln) => [], dotenvs: async (tln) => [], env: async (tln, env) => {}, options: async (tln, args) => { args .prefix('TLN_JENKINS') .option('host', { describe: 'Jenkins host url', default: 'localhost', type: 'string' }) .option('port', { describe: 'Jenkins host port', default: '9080', type: 'string' }) .option('user', { describe: 'Jenkins user', default: 'admin', type: 'string' }) .option('token', { describe: 'User access token', default: null, type: 'string' }) .option('plugins', { describe: 'Space separated list of plugins', default: null, type: 'string' }); }, inherits: async (tln) => [], depends: async (tln) => [], steps: async (tln) => [ { id: 'install', filter: 'ubuntu', builder: async (tln, script) => script.set([` wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list' sudo apt update sudo apt install jenkins -y sudo systemctl start jenkins ` ]) }, { id: 'install-node', filter: 'windows', builder: (tln, script) => script.set([ 'echo ' ]) }, { id: 'install-plugins', filter: 'linux', builder: async (tln, script) => { const host = script.env.TLN_JENKINS_HOST; const port = script.env.TLN_JENKINS_PORT; const user = script.env.TLN_JENKINS_USER; const token = script.env.TLN_JENKINS_TOKEN; const plugins = script.env.TLN_JENKINS_PLUGINS; if (token && plugins){ script.set([ `echo ---- Installing Jenkins plugins ----`, `plugins=(${plugins})`, `for plugin in "\${plugins[@]}"`, `do`, ` echo ---- Installing \${plugin} ----`, ` curl -vvv \\`, ` --user '${user}:${token}' \\`, ` --data "" \\`, ` --header 'Content-Type: text/xml' \\`, ` http://${host}:${port}/pluginManager/installNecessaryPlugins`, ` echo`, `done` ]) } else { script.logger.error(`Password and/or list of plugins were not defined`); } } }, { id: 'generate-jenkinsfile', filter: '', builder: async (tln, script) => { const src = path.join(__dirname, 'Jenkinsfile.template'); const dest = path.join(script.env.TLN_COMPONENT_HOME, 'Jenkinsfile'); if (tln.isWindows()) { script.set([ `copy ${src} ${dest}` ]); } else { script.set([ `cp ${src} ${dest}` ]); } } } ], components: async (tln) => [] }